Hi everyone

I want to return the results of a database query, and assign the values to variables.

The data in the database is as follows:

Item Price
=== ====
item1 10.00
item2 7.00
item3 5.00

I have float variables called item1, item2, item3, and I want to assign these variables the results from the query.


This is the code I have so far. Any help would be appreciated.

try
{
statement = connection.createStatement();
results = statement.executeQuery("SELECT * FROM items");

while (results.next())
{
if(results.getString(1).equals("item1"))
{
item1 = results.getInt(2);
}

else if(results.getString(1).equals("item2"))
{
item2 = results.getInt(2);
}

else if(results.getString(1).equals("item3"))
{
item3 = results.getInt(2);
}
}

}
catch(SQLException sqlEx)
{
System.out.println("* SQL Error! *");
System.exit(1);
}