SqlException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gsuns82
    New Member
    • Mar 2007
    • 58

    SqlException

    hi,
    my java code:
    *************** *
    Code:
     import java.sql.*; 
    public class sqljdbc
    {
    public static void main(String[] args) 
    {
    try
    {
    String url = "jdbc:microsoft:sqlserver://";
    //String serverName = "localhost";
    String serverName = "ow8";
    String portNumber = "1433";
    String databaseName = "sundar";
    String userName = "sa";
    String password = "sa";
    String selectMethod = "cursor"; 
    //String url="jdbc:microsoft:sqlserver://"+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";,"+userName+","+password;
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    Connection conn = DriverManager.getConnection(url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";",userName,password);
    //Connection conn = DriverManager.getConnection(url);
    Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    ResultSet rs=st.executeQuery("select * from paging");
    while(rs.next())
    {
    System.out.println(rs.getString(1));
    } 
    }
    catch (Exception e)
    {
    e.printStackTrace();
     
    }
    }
    }
    EXCEPTION GOT:
    *************** ******

    java.sql.SQLExc eption: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
    at com.microsoft.j dbc.base.BaseEx ceptions.create Exception(Unkno wn Source)
    at com.microsoft.j dbc.base.BaseEx ceptions.getExc eption(Unknown Source)
    at com.microsoft.j dbc.base.BaseEx ceptions.getExc eption(Unknown Source)
    at com.microsoft.j dbc.sqlserver.t ds.TDSConnectio n.<init>(Unknow n Source)
    at com.microsoft.j dbc.sqlserver.S QLServerImplCon nection.open(Un known Source)
    at com.microsoft.j dbc.base.BaseCo nnection.getNew ImplConnection( Unknown Source)
    at com.microsoft.j dbc.base.BaseCo nnection.open(U nknown Source)
    at com.microsoft.j dbc.base.BaseDr iver.connect(Un known Source)
    at java.sql.Driver Manager.getConn ection(DriverMa nager.java:525)
    at java.sql.Driver Manager.getConn ection(DriverMa nager.java:171)
    at sqljdbc.main(sq ljdbc.java:18)

    can any one resolve this exception?????? ???????

    thanks in advance........ .....
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    There could be several reasons for this error. Try the suggestions here and post if there is still a problem.

    Comment

    • gsuns82
      New Member
      • Mar 2007
      • 58

      #3
      Originally posted by r035198x
      There could be several reasons for this error. Try the suggestions here and post if there is still a problem.
      thanks 4 ur reply,
      I have followed the instructions which are given in www.websina.com but still getting the same problem....can u guide me further??? any other solutions???

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Print out that complicated String before you pass it on to the getConnection()
        method. Check if it is correct; it seems it isn't.

        kind regards,

        Jos

        Comment

        • gsuns82
          New Member
          • Mar 2007
          • 58

          #5
          Originally posted by JosAH
          Print out that complicated String before you pass it on to the getConnection()
          method. Check if it is correct; it seems it isn't.

          kind regards,

          Jos


          I tried the following connection url suggested by Microsoft.com but still having the same problem..

          connection urls wic i tried:::
          *************** *************** **
          jdbc:microsoft: sqlserver://localhost:1433; databaseName=su ndar;UserName=s a;Password=sa

          any idea on this url????

          regards,
          suns82.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            This may seem trivial but check it out nevertheless:

            - is your database engine running?
            - does it listen to the port you mentioned?
            - does a user 'sa' (the same password) exist?
            - try 127.0.0.1 instead of localhost.

            kind regards,

            Jos

            Comment

            • gsuns82
              New Member
              • Mar 2007
              • 58

              #7
              Originally posted by JosAH
              This may seem trivial but check it out nevertheless:

              - is your database engine running?
              - does it listen to the port you mentioned?
              - does a user 'sa' (the same password) exist?
              - try 127.0.0.1 instead of localhost.

              kind regards,

              Jos
              thanks Jos,i have tried things wat u mentioned except dns '127.0.0.1',let me try this,this can the final hope...

              regards,
              sundar.

              Comment

              Working...