与SQL Server连接的Android Studio错误

时间:2018-11-02 18:58:29

标签: sql-server android-studio

我正在使用android studio和sql服务器制作一个登录应用程序,但是当我按下按钮登录时,它会向我抛出这个enter image description here

这是我的代码:

公共类ConnectionClass {

list

}

公共类MainActivity扩展了AppCompatActivity {

String ip = "10.11.10.113";
String classs = "net.sourceforge.jtds.jdbc.Driver";
String db = "Andro";
String un = "sas";
String password = "123456";

@SuppressLint("NewApi")
public Connection CONN() {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
    StrictMode.setThreadPolicy(policy);
    Connection conn = null;
    String ConnURL = null;
    try {

        Class.forName(classs);
        ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
                + "databaseName=" + db + ";user=" + un + ";password="
                + password + ";";
        conn = DriverManager.getConnection(ConnURL);
    } catch (SQLException se) {
        Log.e("ERRO", se.getMessage());
    } catch (ClassNotFoundException e) {
        Log.e("ERRO", e.getMessage());
    } catch (Exception e) {
        Log.e("Error connection","" + e.getMessage());
    }
    return conn;
}

}

我修改了xml清单,以便它可以连接到Internet。对这个问题有任何想法吗?

0 个答案:

没有答案