连接到 oracle 10g 数据库时出现 IOException:-
Exception in thread "main" java.sql.SQLException: Io exception: Got minus one from a read call
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:190)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:363)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:401)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:441)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:839)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.myapp.struts.DBConnection.getDBConnection(DBConnection.java:21)
at com.myapp.struts.DBConnection.main(DBConnection.java:31)
Java 结果:1
我的课程代码如下:-
package com.myapp.struts;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DBConnection {
Connection connection = null;
public Connection getDBConnection()throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("OUTPUUT ********driver registered");
connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","system");
System.out.println("OUTPUUT ********connection established");
return connection;
}
public static void main(String args[])throws Exception{
DBConnection db = new DBConnection();
ResultSet result = null;
String query = "SELECT * FROM admin;";
Connection con = null;
con = db.getDBConnection();
System.out.println("OUTPUUT ********111111111");
Statement st =con.createStatement();
result = (ResultSet) st.executeQuery(query);
while(result.next()){
System.out.println("OUTPUUT ********");
System.out.println(result.getInt(1));
System.out.println(result.getString(2));
System.out.println(result.getString(3));
System.out.println(result.getString(4));
}
con.close();
}
}
还有一件事我正在使用netbeans ide并开发一个struts项目。从过去两天开始一直在努力解决这个问题,但尚未得到解决方案。
请帮忙????