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.

  • Strange, now another error: Communications link failure com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure has been 1 ms ago. - Kamenev_D
  • show how url looks like - ermak0ff
  • And after a couple of times the error is returned as in the topic. Not clear ... private static final String url = "jdbc: mysql: //10.239.16.74: 3306 / myfirsbase"; private static final String user = "root"; private static final String password = "root"; - Kamenev_D
  • Do you have an internet connection on your device? - Kirill Stoianov
  • Connection is made in the local network. The reason is different. - Kamenev_D

0