Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBC SQLServer 2000 connection problem

Status
Not open for further replies.

MartinF

Technical User
Sep 19, 2000
143
FR
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();

}

}


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

Cheers,
Dian
 
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?

 
Wrong version of the jdbc driver in your class-path?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top