I am trying to write a code that connects to my SQL database and selects data from it. using Java in Eclipse.
It seems not to be working and i dont know why. Can someone help? This code was written on an android application.
thanks
Kingsley
public void query2()
{
Log.i("Android" , "MySQL Connect Example.");
Connection conn = null;
try {
String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
//test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class;
String connString = "jdbc:jtds:sqlserver://localhost:1433;instance=SQLEXPRESS;databaseName=EDMS;integratedSecurity=true";
//String username = "xxxxxx";
//String password = "xxxxxxxxxx";
conn = DriverManager.getConnection(connString);
Log.w("Connection", "open");
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("select * from Employee");
//Print the data to the console
while(reset.next()){
Log.w("Data: ", reset.getString(3));
// Log.w("Data",reset.getString(2));
//setContentView(reset.toString());
}
conn.close();
} catch (Exception e)
{
Log.w("Error connection","" + e.getMessage());
}
}