Hirdetés

Új hozzászólás Aktív témák

  • Vizinyenyec

    aktív tag

    válasz Vizinyenyec #5516 üzenetére

    Sziasztok!

    Végül sikerült megoldani.
    Nem a hagyományos Java JDBC kapcsolatot használtam hanem az alábbi kódot:

    @SuppressLint("StaticFieldLeak")     public class InfoAsyncTask extends AsyncTask<Void, Void, Map<String, String>> {         @Override         protected Map<String, String> doInBackground(Void... voids) {             Map<String, String> info = new HashMap<>();             try (Connection connection = DriverManager.getConnection(URL, USER, PASSWORD)) {                 String sql = "SELECT name, address, phone_number FROM school_info LIMIT 1";                 PreparedStatement statement = connection.prepareStatement(sql);                 ResultSet resultSet = statement.executeQuery();                 if (resultSet.next()) {                     info.put("name", resultSet.getString("name"));                     info.put("address", resultSet.getString("address"));                     info.put("phone_number", resultSet.getString("phone_number"));                 }                             } catch (Exception e) {                 Log.e("InfoAsyncTask", "Error reading school information", e);             }             return info;         }         @Override         protected void onPostExecute(Map<String, String> result) {             if (!result.isEmpty()) {                 TextView textViewName = findViewById(R.id.textViewName);                 TextView textViewAddress = findViewById(R.id.textViewAddress);                 TextView textViewPhoneNumber = findViewById(R.id.textViewPhone);                 textViewName.setText(result.get("name"));                 textViewAddress.setText(result.get("address"));                 textViewPhoneNumber.setText(result.get("phone_number"));             }         }

Új hozzászólás Aktív témák