JTDS Android连接到SQL Server - 错误连接null

时间:2014-04-29 01:49:06

标签: android sql sql-server null jtds

我试图从我的Android应用程序连接到我的MS SQL Server 2008 R2,这是代码:

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());
}

我在这一行收到错误:

Connection DbConn = DriverManager.getConnection("jdbc:jtds:sqlserver://MYPC/" + DB + ";instance=SQLEXPRESS;user=" + USERNAME + ";password=" + PASSWORD);

在Logcat中使用Error Connection null。我正在使用jtds-1.3.1.jar。我在数据库实例和实际数据库中定义了用户。我启用了TCP / IP,我启用了Windows和SQL身份验证以及允许远程连接。香港专业教育学院查找其他帖子但没有帮助。不知道什么是错的,有什么想法吗?

0 个答案:

没有答案