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();
}
}
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();
}
}