Results 1 to 1 of 1
- 03-11-2008, 04:55 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 1
- Rep Power
- 0
Need help returning data from database
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);
}
Similar Threads
-
Upload excel data to access database
By ravikumar.achi in forum New To JavaReplies: 20Last Post: 01-19-2012, 11:30 AM -
[SOLVED] Getting Data from a database
By AJG in forum New To JavaReplies: 8Last Post: 04-04-2008, 12:52 PM -
Modifying data in database table using PreparedStatement
By Java Tip in forum Java TipReplies: 0Last Post: 02-09-2008, 08:22 PM -
Plz help ... retreiving data from an access database table....
By austinsmiles in forum New To JavaReplies: 1Last Post: 02-01-2008, 01:21 PM -
How to query data from database using SSL
By mano in forum New To JavaReplies: 0Last Post: 08-02-2007, 05:30 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks