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
- BESZÁMÍTÁS! LENOVO ThinkPad P15 Gen 2 munkaállomás - i7 11800H 32GB DDR4 512GB SSD Quadro T1200 W11
- BESZÁMÍTÁS! LENOVO ThinkPad P15 Gen 1 munkaállomás - i7 10875H 32GB DDR4 512GB SSD Quadro T2000 W11
- BESZÁMÍTÁS! LENOVO ThinkPad P15 Gen 1 munkaállomás - i7 10850H 16GB DDR4 256GB SSD Quadro T2000 W11
- Eladó több db külső merevlemez
- BESZÁMÍTÁS! LENOVO ThinkPad P15 Gen 1 munkaállomás - i7 10750H 16GB DDR4 256GB SSD Quadro T1000 W11
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest


