I do not understand what the problem is: Why does this error occur?
try { // System.out.print("String\n"); Class.forName("com.mysql.jdbc.Driver").newInstance(); String query = "select NAME, LASTNAME from myfirsttable"; con = (Connection) DriverManager.getConnection(url, user, password); if (con != null)Toast.makeText(this, "Connected to the database", Toast.LENGTH_SHORT).show(); else Toast.makeText(this, "Not connected to the database", Toast.LENGTH_SHORT).show(); // getting Statement object to execute query stmt = (Statement) con.createStatement(); // executing SELECT query rs = stmt.executeQuery(query); while (rs.next()) { String name = rs.getString("NAME"); String lastname = rs.getString("LASTNAME"); // System.out.printf("Name: %s, Lastname: %s %n", name, lastname); formatter.format("Name: %s, Lastname: %s %n", name, lastname); Toast.makeText(this, formatter.toString(), Toast.LENGTH_SHORT).show(); } } catch (SQLException ex) { // System.out.println("Error = " + ex); Toast.makeText(this, "Error = " + ex, Toast.LENGTH_SHORT).show(); }
Right after
con = (Connection) DriverManager.getConnection(url, user, password);
Fails to a SQLException with the specified error. Spelled out in the manifest
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
On the server side, permissions are given for the user. With the other PC connects without problems. And where can I read about intercepting SQLException errors? What would be on the phone to issue informative errors, and not just a window that the application closes. Thank.