There is a class that connects to the database. It has a read method that immediately transfers data to the collection:
public class Basa_Dannyh { public static ResultSet resSet; public static void ReadDB() throws ClassNotFoundException, SQLException { resSet = statmt.executeQuery("SELECT * FROM nachaltest"); while(resSet.next()) { int id = resSet.getInt("id"); String quest = resSet.getString("quest"); String ansver1 = resSet.getString("ansver1"); String ansver2 = resSet.getString("ansver2"); String ansver3 = resSet.getString("ansver3"); String true_ansver = resSet.getString("true_ansver"); ArrayList<String> test_collection = new ArrayList<String>(); test_collection.add(quest); test_collection.add(ansver1); test_collection.add(ansver2); test_collection.add(ansver3); test_collection.add(true_ansver); for (int i = 0; i<test_collection.size(); i++) { System.out.println(test_collection.get(i)); } } } } Connecting to this method in another class happens like this:
Basa_Dannyh.ReadDB(); I need to transfer the collection to another class. How to do it? Through the creation of a class instance:
Basa_Dannyh bd = new Basa_Dannyh(); Does not work. I try to tighten up in the standard way:
Basa_Dannyh bd = new Basa_Dannyh(); System.out.println(bd.test_collection.get(1)); //Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ Mistake. Does not see test_collection .