×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

JDBC SQLServer 2000 connection problem

JDBC SQLServer 2000 connection problem

JDBC SQLServer 2000 connection problem

(OP)
Hi all,

I have the code below...see bottom of thread

I am using netbeans 6.9, if i just run the file as is, it connects to the DB and disconnects just fine.  However, if i create an instance of this class from within another class and call the QueryDB() method, i get this error:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host XXXXXX, port 1433 has failed. Error: "Malformed reply from SOCKS server. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port."

I am comletely stumped..the connection code obviously works, but only when called from the files main method, but not from outside the class?
public class DB_Connection {

     private java.sql.Connection  con = null;
     private final String url = "jdbc:sqlserver://XXXXXXX:1433;databaseName=XXXX;integratedSecurity=true";

     private final String selectMethod = "cursor";


     public DB_Connection(){}


     public java.sql.Connection getConnection(){
          try{
               Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
               con = java.sql.DriverManager.getConnection(url);
               if(con!=null) System.out.println("DB connected...");
          }catch(Exception e){
               System.out.println("Error Trace in getConnection() : " + e.toString());
         }
          return con;
      }



     public void QueryDB({

        con = this.getConnection();

        try{

            if(con!=null){

                closeConnection();

               }else System.out.println("Error: No active Connection");

          }catch(Exception e){}


     }


     public void closeConnection(){
          try{

               if(con!=null)
                    con.close();
               con=null;
               System.out.println("DB disconnected.");

          }catch(Exception e){}

     }


     public static void main(String[] args) throws Exception {

          DB_Connection myDbTest = new DB_Connection();
          myDbTest.QueryDB();

       }

}


 

RE: JDBC SQLServer 2000 connection problem

Are you executing both inside NetBeans? Maybe it's a problem with firewall permissions

Cheers,
Dian

RE: JDBC SQLServer 2000 connection problem

(OP)
Hi Dian,

When it works i am using 'Run file' option within netbeans just to run that java file.  When it does NOT work i am running the whole application after a clean and build.  Does this off anymore clues?

 

RE: JDBC SQLServer 2000 connection problem

Wrong version of the jdbc driver in your class-path?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close