tags:

views:

39

answers:

2

I am working on a java project and I need to pull some values out of a database and turn them into variables the program will then use to make a billing statement. I can get the program to connect to the database just fine, and the mySQL statement to call the data I need is easy enough. I just can't seem to figure out how to then have it put each field returned in the resultset into a separate variable.

+3  A: 

You should review the JDBC tutorial, and this section answers your question.

+1  A: 

Shamelessly lifted from the jdbc tutorial

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                                         ResultSet.CONCUR_READ_ONLY);
    ResultSet srs = stmt.executeQuery(
        "SELECT COF_NAME, PRICE FROM COFFEES");
    while (srs.next()) {
            String name = srs.getString("COF_NAME");
            float price = srs.getFloat("PRICE");
            System.out.println(name + "     " + price);
    }
ennuikiller