我尝试使用以下代码从 Eclipse 模拟器 Android 连接到 SQL 服务器:
String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
String connString = "jdbc:jtds:sqlserver://83.212.240.15:1521/hua;encrypt=fasle;user=xxxxxx;password=xxx;instance=SQLEXPRESS;";
String username = "xxxxx";
String password = "xxxxx";
conn = DriverManager.getConnection(connString,username,password);
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("insert into picture values('hi');");
conn.close();
但我有以下错误
Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cebcd0 that was originally bound here
android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d64ec0 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.(LoadedApk.java:969)
我已经授予了互联网权限,并且我也将 jtds-1.3.0.jar 放入了 lib 文件夹中。有什么想法吗?
提前致谢
最佳答案
您收到该错误是因为您正在使用 stmt.executeQuery。
stmt.executeQuery 期望返回一些内容(这意味着 SELECT 的结果),但您正在插入数据,而不是查询,因此您应该使用 stmt.executeUpdate 代替
关于java - Android连接sql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17136112/