用JDBC通过thin访问Oracle数据库,出现一下异常,求解决方法!!万分感激!!!
java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153093632)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at phonenbr.PhoneNbr.main(PhoneNbr.java:33)
Exception in thread "main"
解决方案 »
- Java实现发现现网络中的活动主机
- 请教关于用comparable实现list排序的问题,请高手们帮我解答一下
- 图片为什么显示不了?
- System.out.println(Arrays.binarySearch(new char[]{'0','1','i','I','l','o','O'}, 'i')); 为什么是-5?
- java 多媒体
- 关于哈夫曼树的问题(急用)
- 如何用java得到文件的owner?在线等,急急!!!!谢谢!!(当时给分)
- 用APPLET来开发一个网上成绩管理系统,会不会很白痴??
- 关于JAVA文件执行时出现的错误
- 子类构造函数问题
- 今天面试题没思路,大家帮看一下!
- 日期字符串转成日期型的问题
访问权限有吗;
先在SQL-PLUS里面试一下
我的数据库访问代码如下,端口,主机名都配置正确了的。数据库驱动是正确的。
class PhoneNbr
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); // Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as <host>:<port>:<sid>. The example uses the short cut syntax.
String url = "jdbc:oracle:thin:@192.168.0.56:1521:newyeskaron";
String userName = "newyes";
String password = "abcde12345"; // if (args.length > 0) url = args[0];
// if (args.length > 1) userName = args[1];
//if (args.length > 2) password = args[2]; Connection conn =
DriverManager.getConnection (url, userName, password); // Create a Statement
Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select * from stu_info where phone_nbr='65107569'"); // Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
Connection con = null;
Statement stmt = null;
try {
DriverManager.registerDriver(new OracleDriver());
} catch (SQLException e5) {
e5.printStackTrace();
}
try {
String driverName = "oracle.jdbc.driver.OracleDriver"; Class.forName(driverName); } catch (ClassNotFoundException e) {
e.printStackTrace();
}
// String serverName = "192.168.1.91";
// String serverPort = "1521";
// String serverID = "oracl";
// String userName = "goa";
// String userPsw = "goa";
String url="jdbc:oracle:thin:@192.168.1.91:1521:oracl";
try {
con = DriverManager.getConnection(url, "goa", "goa");
} catch (SQLException e1) { e1.printStackTrace();
}
try {
stmt = con.createStatement();
} catch (SQLException e2) {
e2.printStackTrace();
}
String createTable = "create table test_table "
+ "(id varchar2(32), name varchar2(32),sex int) ";
System.out.println("createTable---------" + createTable);
try {
stmt.executeUpdate(createTable);
} catch (SQLException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
try {
stmt.executeUpdate("insert into test_table "
+ "values('20050713001','小军',1)");
} catch (SQLException e4) {
e4.printStackTrace();
}
}