0

i had an array list statically like

    List l=new ArrayList();
      l.add("1");
      l.add("2");
      l.add("3");
      l.add("4");
      l.add("5");

but i want to get the database column values in to my array list dynamically how this can be achieved please suggest me this im using oracle xe

2
  • Have you succeeded to get data out of database? Commented Feb 18, 2013 at 17:32
  • While it is not related to your particular question, I would strongly urge you to use generics: List<String> l = new ArrayList<String>();. There is no reason to avoid the extra type-safety and clarity it gives you. Commented Feb 18, 2013 at 17:42

1 Answer 1

1

The standard way to connect to databases in Java is JDBC, and Sun publishes a JDBC basics lesson.

In your case, the very rough solution would be something like the following:

List l=new ArrayList();

// TODO handle exceptions
Connection conn = ...; // create the connection according to your DB details
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select Column from YourTable");
while (rs.next()) {
    l.add(rs.getString(1));
}
// TODO close these in a finally block
rs.close();
stmt.close();
Sign up to request clarification or add additional context in comments.

Comments

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.