MsSQL连接总是在android中返回null

时间:2014-04-28 17:00:10

标签: android sql-server jtds

我有这段代码:

public void update() {
        Log.i("Android", " MySQL Connect Example.");
        Connection conn = null;

        try {
            String driver = "net.sourceforge.jtds.jdbc.Driver";
            Class.forName(driver).newInstance();
            // test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class;
            String connString = "jdbc:jtds:sqlserver://my_ip:1433;instance=SQLEXPRESS;databaseName=Kukasauto_adatgyujto;user=***;password=***";
            String username = "***";
            String password = "***";
            conn = DriverManager.getConnection(connString, username, password);
            Log.w("Connection", "open");
            Statement stmt = conn.createStatement();
            ResultSet reset = stmt
                    .executeQuery("select * from dbo.Unit_Vocab;");
            // Print the data to the console
            while (reset.next()) {
                Log.w("Data:", reset.getString(1));
                // Log.w("Data",reset.getString(2));
            }
            conn.close();
        } catch (Exception e) {
            Log.w("Error connection", "" + e.getMessage());
        }
    }

它适用于PC上的netbeans,但不适用于android。 我总是异常= null。

你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

取代了

Log.w("Error connection", "" + e.getMessage());

Log.w("Error connection", "" + e.printStackTrace());

然后打印错误:strict mode...