问题
hi im trying to connect to my MS SQL Server 2008 R2 from my Android application this is the code:
try {
Log.i("Login", "Establishing Connection...");
// SET CONNECTIONSTRING
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
Log.i("JDBC","found");
Connection DbConn = DriverManager.getConnection("jdbc:jtds:sqlserver://MYPC/" + DB + ";instance=SQLEXPRESS;user=" + USERNAME + ";password=" + PASSWORD);
Log.i("Login","Connected");
Statement stmt = DbConn.createStatement();
ResultSet insert = stmt.executeQuery("insert into UserLogin(username, password) values (admin, admin);");
ResultSet reset = stmt.executeQuery(" select * from UserLogin ");
Toast.makeText(this, reset.getString(1), Toast.LENGTH_SHORT).show();
DbConn.close();
// go to newsfeed
} catch (Exception e) {
Log.e("Error connection","" + e.getMessage());
}
im getting an error at this line:
Connection DbConn = DriverManager.getConnection("jdbc:jtds:sqlserver://MYPC/" + DB + ";instance=SQLEXPRESS;user=" + USERNAME + ";password=" + PASSWORD);
with Error Connection null in the Logcat. Im using jtds-1.3.1.jar. i have the user defined in the database instance and the actual database. i have TCP/IP enabled, and i have i have Windows and SQL authentication enabled as well as allowed remote connections. ive looked up other posts but no help. not sure what's wrong, any ideas?
来源:https://stackoverflow.com/questions/23354129/jtds-android-connect-to-sql-server-error-connection-null