Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-11-2008, 06:55 PM
Member
 
Join Date: Mar 2008
Posts: 1
dyn03 is on a distinguished road
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
Sponsored Links
Reply


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

vB 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 02:52 PM
Modifying data in database table using PreparedStatement Java Tip Java Tips 0 02-09-2008 10:22 PM
Plz help ... retreiving data from an access database table.... austinsmiles New To Java 1 02-01-2008 03:21 PM
Upload excel data to access database ravikumar.achi New To Java 0 11-12-2007 03:52 PM
How to query data from database using SSL mano New To Java 0 08-02-2007 07:30 PM


All times are GMT +3. The time now is 02:38 AM.


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