This discussion is archived
2 Replies Latest reply: Oct 3, 2012 6:41 PM by EJP RSS

java.sql.SQLException: Socket read timed out

913779 Newbie
Currently Being Moderated
// DbTest.java

import java.sql.*;
import java.io.*;

public class DbTest
{
     public static void main(String args[])
     {
          System.out.println("DbTest main(-)");
          Connection con = null;
          try
          {
               Class.forName("oracle.jdbc.driver.OracleDriver");
               System.out.println("class loaded");
               con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcldb","scott","tiger");
               System.out.println("con obj created");
               
               /*Class.forName("com.mysql.jdbc.Driver");
               System.out.println("Driver loaded");
               con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","root");
               */
               System.out.println("con obj retrived");
               if (con!=null)
               {
                    System.out.println("Connection created successfully");

               }
               else
               {
                    System.out.println("Connection refused");
               }
          }
          catch (SQLException e)
          {
               e.printStackTrace();
          }
          catch(Exception e)
          {
               e.printStackTrace();     
          }
     }
}
e:\JavaPrgms\JDBC>java DbTest
DbTest main(-)
class loaded
java.sql.SQLException: Socket read timed out
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:
531)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtensio
n.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at DbTest.main(DbTest.java:17)
Caused by: oracle.net.ns.NetException: Socket read timed out
at oracle.net.ns.Packet.receive(Packet.java:320)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:286)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
... 7 more

e:\JavaPrgms\JDBC>

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points