Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-11-2008, 05:55 PM
Member
 
Join Date: Mar 2008
Posts: 1
Rep Power: 0
dyn03 is on a distinguished road
Default 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);
}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Getting Data from a database AJG New To Java 8 04-04-2008 01:52 PM
Modifying data in database table using PreparedStatement Java Tip Java Tips 0 02-09-2008 09:22 PM
Plz help ... retreiving data from an access database table.... austinsmiles New To Java 1 02-01-2008 02:21 PM
Upload excel data to access database ravikumar.achi New To Java 0 11-12-2007 02:52 PM
How to query data from database using SSL mano New To Java 0 08-02-2007 06:30 PM


All times are GMT +2. The time now is 09:33 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org