the following code is generating an error on the variable con2 saying "non-static variable con2 cannot be referenced from a static context Error." I googled for a resolution and they are suggesting the variable isn't initalized yet to make the methods available. Am I initializing this incorrectly? i also tried changing things to public but that didn't help either. thanks in advance
import java.io.*;
import java.net.*;
import java.sql.*;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import net.sourceforge.jtds.jdbcx.JtdsDataSource;
import net.sourceforge.jtds.jdbc.Driver;
class testconnect {
private java.sql.Connection con2 = null;
private final String url2 = "jdbc:jtds:sqlserver://";
private final String serverName= "SQL01";
private final String portNumber = "2677";
private final String databaseName= "App";
private final String userName = "bob";
private final String password = "boob";
private final String selectMethod = "cursor";
private String getConnectionUrl2(){
System.out.println("initalizing jtds");
//String returnVal = url+serverName+":"+portNumber+";databaseName="+databaseName+";user="+userName+";password="+password+";instance="+instance+";";
String returnVal = url2+serverName+":"+portNumber+"/"+databaseName+";user="+userName+";password="+password;
System.out.println("url2: " + returnVal);
return returnVal;
}
public static void main (String[] args) {
con2 = java.sql.DriverManager.getConnection(getConnectionUrl2());
}
} //end class