I'm making an app in android studio with connection to a SQL database server, I have a problem in connecting to the database.
Code:
import android.util.Log; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import net.sourceforge.jtds.jdbc.*;
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/quehojaes;encrypt=false;user=Pc-PC;password=;instance=SQLEXPRESS;";
// String connString = "Data Source=localhost:1433;Initial Catalog=quehojaes;Integrated Security=True";
String connString ="jdbc:jtds:sqlserver://localhost:1433/quehojaes;";
String username = "Pc-PC";
String password = "";
conn = DriverManager.getConnection(connString);
Log.w("Connection", "open");
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("select * from planta where id=1");
//Print the data to the console
while (reset.next()) {
dato = reset.getString(3);
Log.w("Data:", reset.getString(3));
Log.w("Data",reset.getString(2));
}
conn.close();
} catch (Exception e) {
Log.w("Error connection", "" + e.getMessage());
}
return dato;
}
.................................
I got an error at line (conn = DriverManager.getConnection (connString)), so I guess it is wrong user I'm trying to get into the database, I enter Windows user authentication with a local database and I have no password for that user called Pc.
There are lines discussed by failed login attempts I've tried.
Thanks for the help!