MsSQL连接在android中总是返回null
我有以下代码:MsSQL连接在android中总是返回null,android,sql-server,jtds,Android,Sql Server,Jtds,我有以下代码: public void update() { Log.i("Android", " MySQL Connect Example."); Connection conn = null; try { String driver = "net.sourceforge.jtds.jdbc.Driver"; Class.forName(driver).newInstance();
public void update() {
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://my_ip:1433;instance=SQLEXPRESS;databaseName=Kukasauto_adatgyujto;user=***;password=***";
String username = "***";
String password = "***";
conn = DriverManager.getConnection(connString, username, password);
Log.w("Connection", "open");
Statement stmt = conn.createStatement();
ResultSet reset = stmt
.executeQuery("select * from dbo.Unit_Vocab;");
// Print the data to the console
while (reset.next()) {
Log.w("Data:", reset.getString(1));
// Log.w("Data",reset.getString(2));
}
conn.close();
} catch (Exception e) {
Log.w("Error connection", "" + e.getMessage());
}
}
它可以在pc上使用netbeans,但不能在android上使用。
我总是得到exception=null
你能告诉我为什么吗?我找到了解决方案: 取代
Log.w("Error connection", "" + e.getMessage());
到
然后打印错误:
strict mode…
这个MySql怎么样?是MySql还是mssql?你确定可以从android设备访问my_ip
?(提示:可能不会)另外,不要只打印异常消息
。打印完整的stacktrace。它只打印“null”,它是mssql
Log.w("Error connection", "" + e.printStackTrace());