JTDS Android connect to SQL Server - Error Connection null

回眸只為那壹抹淺笑 提交于 2019-12-23 21:03:14

问题


hi im trying to connect to my MS SQL Server 2008 R2 from my Android application this is the code:

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

im getting an error at this line:

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

with Error Connection null in the Logcat. Im using jtds-1.3.1.jar. i have the user defined in the database instance and the actual database. i have TCP/IP enabled, and i have i have Windows and SQL authentication enabled as well as allowed remote connections. ive looked up other posts but no help. not sure what's wrong, any ideas?

来源:https://stackoverflow.com/questions/23354129/jtds-android-connect-to-sql-server-error-connection-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!