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
- HIBÁTLAN iPhone 14 512GB Blue -1 ÉV GARANCIA - Kártyafüggetlen, MS3922
- Xiaomi Mijia Smart Socket Plug kínai WIFI-set keresek
- 160 - 177 - 178 - Lenovo LOQ (15IRX9) - Intel Core i7-13650HX, RTX 4060 (ELKELT)
- Eladó Google Pixel 9 Pro 16/256GB / Ajándék fólia és tok! / Akku 100% / 24 hó jótállás
- GYÖNYÖRŰ iPhone 13 mini 128GB Blue -1 ÉV GARANCIA -Kártyafüggetlen, MS3884, 100% Akkumulátor
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Central PC számítógép és laptop szerviz - Pécs
Város: Pécs


