Ú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
- Telefon felvásárlás!! iPhone 16/iPhone 16 Plus/iPhone 16 Pro/iPhone 16 Pro Max
- Apple iPhone 16 Pro Max Desert Titanium 256GB használt karcmentes 89% akku (405 ciklus) 6 hónap
- HP EliteBook 830 G8 13,3" i7 -1185 G7, 8-16GB RAM, SSD, jó akku, számla, 6 hó gar
- 27%! LG 86UR76006LC (86") UHD (Active HDR, 60 Hz, Smart TV)
- Oneplus 9 128GB,Átlagos,Adatkabel,12 hónap garanciával
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest

