Question

i have this code:

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

it works with netbeans on pc, but not works on android. i always got exception = null.

can you help me why?

Was it helpful?

Solution

I've found the solution:

replaced the

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

to

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

then it print the error: strict mode...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top