[英]getting IOException “got minus one from a read call” while connecting to oracle 10g database
getting IOException while connecting to oracle 10g database:- 连接到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 Result: 1 Java结果:1
my class code is following:- 我的班级代码如下: -
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();
}
}
AND one more thing i am using netbeans ide and developing a struts project. 还有一件事我正在使用netbeans ide并开发一个struts项目。 Struggling with this problem from last two days but yet to get the solution.
在过去的两天里遇到了这个问题,但尚未得到解决方案。
Please help???? 请帮忙????
if Facing problem to connect with Oracle 10g using JDBC, try below things: 1. turn off your machines's Wi-fi. 如果面临使用JDBC连接Oracle 10g的问题,请尝试以下事项:1。关闭机器的Wi-Fi。 2. Stop Oracle Service.
2.停止Oracle服务。 3. Start Oracle Service.
3.启动Oracle服务。 Now try to connect with DataBase using JDBC.
现在尝试使用JDBC连接DataBase。 Problem will be resolved now.
问题现在就解决了。
尝试在查询结束时删除分号
String query = "SELECT * FROM admin";
I got the problem solved just by replacing the connection url as: connection = DriverManager.getConnection("jdbc:oracle:thin:@//127.0.0.1:1521/XE","system","system"); 我只是通过将连接URL替换为:connection = DriverManager.getConnection(“jdbc:oracle:thin:@ // 127.0.0.1:1521/XE","system","sy stem”)来解决问题; thanks to everyone for your support.
感谢大家的支持。
Try this url instead 请尝试使用此网址
"jdbc:oracle:thin:@//localhost:1521/XE"
or, "jdbc:oracle:thin:@//localhost:1521/xe"
或者,
"jdbc:oracle:thin:@//localhost:1521/xe"
You might also want to try this to track down your problem - 您可能还想尝试这个来追踪您的问题 -
Remove the following while section temporarily 暂时删除以下部分
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)); }
result.first();
result.first();
System.out.println(result.getString(1));
System.out.println(result.getString(1));
Is a kind of trial and error answer. 是一种反复试验的答案。
Hope this helps. 希望这可以帮助。
如果执行数据库关闭命令,则它将不再允许新连接,并且将出现此错误。
我也遇到了同样的问题,我通过将8080端口替换为1521来解决它问题谢谢大家对我这样的初学者都做得很好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.