连接MSSQL与jtds在Android中出错

时间:2014-05-14 08:09:22

标签: android mssql-jdbc

我想与jtds建立连接,但是我遇到了一个错误,例如AsyncTask#1 RuntimeException执行doInBackground时出错。

我该如何修复?

public class dbHelper extends AsyncTask<Void, Void, Void>  {

public dbHelper() throws SQLException, ClassNotFoundException {

}

@Override
protected Void doInBackground(Void... params) {
    try {
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        Log.i("hata:","1");
        ResultSet results;
        Log.i("hata:","2");
        Connection con=DriverManager.getConnection("jdbc:jtds:sqlserver://10.0.2.2:1433","mrt","112233mrt");
        Log.i("hata:","3");
        Statement st=con.createStatement();
        Log.i("hata:","4");
        results=st.executeQuery("SELECT * FROM cinema.dbo.DBO_Users");
        Log.i("hata:","5");
        while(results.next())
        {
            String a=results.getString("username");
            Log.i("gelen:",a);
        }
        con.close(); 
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    return null;
}

}

0 个答案:

没有答案