SQL Question in Java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashkash
    New Member
    • Jul 2006
    • 6

    #1

    SQL Question in Java

    I am executing an SQL statement in Java and want the results to be stored in a list. The statement is as follows:

    SELECT CASE,DATE FROM ...

    Will this be stored in the list as CASE,DATE for each entry in the list? Would the list look something like this,

    CASE,DATE
    CASE,DATE
    CASE,DATE
    ...

    where CASE,DATE are the results retrieved from the DB and each one is a new entry in the list? If not, is there anyway to get it to store the retreived data in a list like above? thanks.
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    The basic way to connect to a database in Java is to use the JDBC. You should take the tutorial: http://java.sun.com/docs/books/tutorial/jdbc/index.html

    When an SQL query is executed the result is a java.sql.Result Set, which is more like an iterator than a list. What you typically do is define a Class that encapsulates the data of one row, and produce your own list of objects by iterating through the ResultSet.

    Comment

    Working...