It does not connect to the database via jdbc on android below 5.0. On 5, 6, everything works. DB mysql. Here is the code:

try { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql://xxxxxxxx:3306/xxxxxxxx", getString(R.string.login), getString(R.string.pasword)); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("SELECT COUNT(1) FROM smm"); while (rs.next()) { l = new Integer(rs.getInt(1)); } Log.i(TAG,"dbtest-1" +String.valueOf(l)); } catch (Exception e) { e.printStackTrace(); } 

Many have tried, help, please.

  • one
    And does not give any error? .. In this case, practically nothing can be done. - Yuriy SPb
  • It gives an error later when it compares the received value with another variable. Just gets nothing from the database. The interesting thing is that with normal people and with 3.0 jdbc works. - Alexander Klimov
  • I personally did not work with this, but, in general, if the database is on a server, would it not be better to retrieve data from a php script from it? And then you should write down in the application the log-pass to the database, and its thread from the market will decompile and erase the database ... - YuriySPb
  • Try not to use ThreadPolicy , but make an appeal to the database in a separate thread - ermak0ff
  • I tried to remove threadpolycy and in a separate thread, it does not rob. - Alexander Klimov

0