欢迎来到知了堂!
联系电话:知了堂-电话号码 028-62016472

SSHManager类报错:com.jcraft.jsch.JSchException: UnknownH-知了堂

SSHManager类报错:com.jcraft.jsch.JSchException: UnknownH

我使用的一个SSHManager类如下:

package me.leaver.Util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

public class SSHManager {
private static final Logger LOGGER = Logger.getLogger(SSHManager.class
.getName());
private JSch jschSSHChannel;
private String strUserName;
private String strConnectionIP;
private int intConnectionPort;
private String strPassword;
private Session sesConnection;
private int intTimeOut;

private void doCommonConstructorActions(String userName, String password,
        String connectionIP, String knownHostsFileName) {
    jschSSHChannel = new JSch();

    try {
        jschSSHChannel.setKnownHosts(knownHostsFileName);
    } catch (JSchException jschX) {
        logError(jschX.getMessage());
    }

    strUserName = userName;
    strPassword = password;
    strConnectionIP = connectionIP;
}

public SSHManager(String userName, String password, String connectionIP,
        String knownHostsFileName) {
    doCommonConstructorActions(userName, password, connectionIP,
            knownHostsFileName);
    intConnectionPort = 22;
    intTimeOut = 60000;
}

public SSHManager(String userName, String password, String connectionIP,
        String knownHostsFileName, int connectionPort) {
    doCommonConstructorActions(userName, password, connectionIP,
            knownHostsFileName);
    intConnectionPort = connectionPort;
    intTimeOut = 60000;
}

public SSHManager(String userName, String password, String connectionIP,
        String knownHostsFileName, int connectionPort,
        int timeOutMilliseconds) {
    doCommonConstructorActions(userName, password, connectionIP,
            knownHostsFileName);
    intConnectionPort = connectionPort;
    intTimeOut = timeOutMilliseconds;
}

public String connect() {
    String errorMessage = null;

    try {
        sesConnection = jschSSHChannel.getSession(strUserName,
                strConnectionIP, intConnectionPort);
        Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        sesConnection.setConfig(config);
        sesConnection.setPassword(strPassword);
        sesConnection.connect(intTimeOut);
    } catch (JSchException jschX) {
        errorMessage = jschX.getMessage();
    }

    return errorMessage;
}

private String logError(String errorMessage) {
    if (errorMessage != null) {
        LOGGER.log(Level.SEVERE, "{0}:{1} - {2}", new Object[] {
                strConnectionIP, intConnectionPort, errorMessage });
    }

    return errorMessage;
}

private String logWarning(String warnMessage) {
    if (warnMessage != null) {
        LOGGER.log(Level.WARNING, "{0}:{1} - {2}", new Object[] {
                strConnectionIP, intConnectionPort, warnMessage });
    }

    return warnMessage;
}

public String sendCommand(String command) {
    StringBuilder outputBuffer = new StringBuilder();

    try {
        Channel channel = sesConnection.openChannel("exec");
        ((ChannelExec) channel).setCommand(command);
        channel.connect();
        InputStream commandOutput = channel.getInputStream();
        int readByte = commandOutput.read();

        while (readByte != 0xffffffff) {
            outputBuffer.append((char) readByte);
            readByte = commandOutput.read();
        }

        channel.disconnect();
    } catch (IOException ioX) {
        logWarning(ioX.getMessage());
        return null;
    } catch (JSchException jschX) {
        logWarning(jschX.getMessage());
        return null;
    }

    return outputBuffer.toString();
}

public void close() {
    sesConnection.disconnect();
}

}

报这个错是因为

public String connect() {
        String errorMessage = null;

    try {
        sesConnection = jschSSHChannel.getSession(strUserName,
                strConnectionIP, intConnectionPort);
        Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        sesConnection.setConfig(config);
        sesConnection.setPassword(strPassword);
        sesConnection.connect(intTimeOut);
    } catch (JSchException jschX) {
        errorMessage = jschX.getMessage();
    }

    return errorMessage;
}</pre>

连接这段代码里少了config.put(“StrictHostKeyChecking”, “no”);这段设置,这个是去掉了严格的安全检查,一般只用于测试目的。

navicat连接oracle数据库

之前使用PL/SQL操作Oracle数据库,使用Heidisql操作mysql数据库。。切换麻烦。而且PL/SQL搜索的时候中文有问题。于是打算使用navicat统一管理

方法是:

1.首先下载Instant Client 的32位版本和Navicat Premium

2.然后解压Instant Client,配置navicat
知了堂Java技术交流

选择oci文件即可

然后新建oracle配置,选择basic模式,其他的根据你的数据库信息自己填写即可。