I am using netbeans and jdk 7 updt 9 with 1.7 and following is my code.
public class jd {
public static void main(String[] args) throws ClassNotFoundException, SQLException
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1158:ORCL","system", "system");
System.out.println("Connection successful");
// Statement s = con.createStatement();
}
}
output is
run:
Exception in thread "main" java.sql.SQLRecoverableException: IO Error: Got minus one from a read call
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:715)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at jd.main(jd.java:22)
Caused by: oracle.net.ns.NetException: Got minus one from a read call
at oracle.net.ns.Packet.receive(Packet.java:314)
at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:153)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:263)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
... 7 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
DriverManager throws this error when it tries to get a connection with invalid URL. Make sure your URL is valid. Things to checkout:
"jdbc:oracle:thin:@localhost:1521:YourDbName"I think the error is in the port number 1158 in this line:
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1158:ORCL","system", "system");
Normally you connect to an Oracle database using port 1521. Try replacing 1158 with 1521.
Your database may be running the Enterprise Manager on port 1158. That's a web application that you access, often by navigating to https://localhost:1158/em. The Oracle database itself will typically be listening on port 1521.
When using JDBC you need to connect direct to the database, not to some web application instead. The Oracle JDBC driver understands the proprietary binary protocol it uses to communicate with the database, but it doesn't understand the HTTP it gets back from the Enterprise Manager web application. Hence you get an odd network error. You can expect similar random network errors if you attempt to connect the JDBC driver to something else that isn't an Oracle database either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With