0

I save some values from database using this function (i've been replaced Vector, because is deprecated) :

// database function
public ArrayList<String[]> selectQuery(String query) {
    ArrayList<String[]> v = null;
    String [] record;
    int colonne = 0;
    try {
        Statement stmt = db.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        v = new ArrayList<String[]>();
        ResultSetMetaData rsmd = rs.getMetaData();
        colonne = rsmd.getColumnCount();

        while(rs.next()) {
            record=new String[colonne];
            for (int i=0; i<colonne; i++) record[i] = rs.getString(i+1);
            v.add((String[])record);
        }
        rs.close();
        stmt.close();
    } catch (Exception e) { e.printStackTrace(); errore = e.getMessage(); }

    return v;
}

// here i print the result, after call that function
ArrayList db_result=null;
db_result=mydb.selectQuery("SELECT titolo, user, date FROM articles WHERE category='1' ORDER by ID ASC");

int i=0;
while (i<db_result.size() ) {
    affitta_3.createLabel().setLabel(db_result.get(i)[0]);
    affitta_3.createLabel().setLabel(db_result.get(i)[1]);
    affitta_3.createLabel().setLabel(db_result.get(i)[2]);
    affitta_3.createLabel().setLabel(db_result.get(i)[3]);
   i++;
}

So, i save many String-array in an array. Now, how can I get (for example) the 4° value from the 2° Array String?

1
  • "...arrays and generics do not mix well." -- Joshua Bloch, Effective Java Second Edition, p. 119. Also implicit in this is arrays and collections not mixing well, due to generics. Commented Nov 16, 2010 at 21:26

1 Answer 1

1

Why are you bothering to clone the string array when nothing else will have a reference to it?

Anyway, you'd get at the string using:

String value = v.get(1)[3];

(assuming that v is of type List<String[]> or something similar).

Sign up to request clarification or add additional context in comments.

3 Comments

uhm. if i have record=(String) db_result.get(0)[0]; it doesnt work (String [] record)
take a look at the updated topic. Maybe is clear :) if i do it it says "array required, by java.lang.Object found"
ok solved. :) db_result.get(i)[0] and ArrayList<String[]> db_result=null; thanks you help me :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.