public class ConnectionClass {
String ip = "192.168.1.99";
String classs = "net.sourceforge.jtds.jdbc.Driver";
String db = "androidtest";
String un = "mytestuser";
String password = "db123456";
@SuppressLint("NewApi")
public Connection CONN() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
try {
Class.forName(classs);
ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
+ "databaseName=" + db + ";user=" + un + ";password="
+ password + ";";
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return conn;
}
}
logcat的:
12-22 09:39:09.181 12516-12532/hitesh.sqlapp W/EGL_emulation: eglSurfaceAttrib not implemented
12-22 09:39:09.181 12516-12532/hitesh.sqlapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa502a800, error=EGL_SUCCESS
12-22 09:39:19.725 12516-12523/hitesh.sqlapp W/art: Suspending all threads took: 13.920ms
我连接SQL Management Studio这个测试用户,但Android模拟器提供" Invalid Credentials"错误。如何解决这个问题?
编辑:连接成功。