[英]MsSQL connection always return null in android
我有此代码:
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。 我总是有例外= null。
你能帮我为什么吗?
我找到了解决方案:
取代了
Log.w("Error connection", "" + e.getMessage());
至
Log.w("Error connection", "" + e.printStackTrace());
然后显示错误: strict mode...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.