我与使用Netbeans或SQuirrel等客户端的Oracle DB连接有问题。 我的操作系统是Windows 7。
我在这个测试用例已停用的防火墙后面。
如果我尝试使用普通的java连接到数据库,如:
public static void main(String[] args) {
Connection connection = null;
try {
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
// Create a connection to the database
String serverName = "servername";
String portNumber = "1521";
String sid = "sid";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + "/" + sid;
String username = "user";
String password = "pass";
connection = DriverManager.getConnection(url, username, password);
System.out.println(url);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
} finally {
try {
System.out.println("connection read only:" + connection.isReadOnly());
System.out.println("connection closed:" + connection.isClosed());
System.out.println("connection isValid:" + connection.isValid(500));
connection.close();
System.out.println("connection closed:" + connection.isClosed());
} catch (SQLException ex) {
Logger.getLogger(JavaApplication3.class.getName()).log(Level.SEVERE, null, ex);
}
}
输出结果为:
URL
connection read only:false
connection closed:false
connection isValid:true
connection closed:true
所以,这很好。
但如果我尝试通过任何工具如Netbeans连接,Squirrel我总是会遇到错误,如
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the Connection
// ...
Caused by: java.net.SocketException: Malformed reply from SOCKS erver
我不知道下一步该怎么做..任何好的暗示我接下来可以尝试什么?