Hy i have the following code :
import java.sql.*;
import java.net.*;
public class binsz {
public void dbConnect(String db_connect_string, String username, String password) {
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(db_connect_string, username, password);
// System.out.println("connected");
}
catch (Exception e) {
e.printStackTrace();
}
}
public void dbQuery(String query) {
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
String db_name = "sqlserver.local";
String username = "sa";
String password = "passwordforsa";
String connection = "jdbc:jtds:sqlserver://" + db_name;
Connection conn = null;
binsz db = new binsz();
db.dbConnect(connection, username, password);
String query = "SELECT TOP 2 * FROM aux..table_name";
db.dbQuery(query);
}
}
and it gives an error while compiling it :
binsz.java:20: cannot find symbol
symbol : variable conn
location: class sip_bins
Statement stmt = conn.createStatement();
^
1 error
How can I use binsz db = new binsz(); to execute a query and retrieve it’s values .
Thanks
PS: the connection to the database is working .. (it prints “connected” if I uncomment that line) ..
This is pretty awful code – useless as written. You’ve got a lot of work to do.
I’d recommend that you study this and throw your code away: