Solved

What would the code to do this database?

Posted on 2004-05-01
4
205 Views
Last Modified: 2010-03-31
This is the database:

COF_NAME      SUP_ID      PRICE   SALES    TOTAL
--------            ------       -----      -----   -----
Colombian            101      7.99      75      0
French_Roast      49      8.99      10      0
Espresso            150      9.99      60      0


What is the output of this code if i run it against this database.

String query = "SELECT COF_NAME, SALES FROM COFFEES " +  
      "WHERE SALES >=40";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
      String s = rs.getString("COF_NAME");
      int n = rs.getInt("SALES");
      System.out.println(n + " pounds of " + s + " sold this week.");
0
Comment
Question by:aquemini001
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
maheshexp earned 20 total points
ID: 10969926
>String query = "SELECT COF_NAME, SALES FROM COFFEES " +  
     "WHERE SALES >=40";

selects all rows where, the SALES is > 40

>>while (rs.next()) {
>>     String s = rs.getString("COF_NAME");
>>     int n = rs.getInt("SALES");
>>     System.out.println(n + " pounds of " + s + " sold this week.");

moves thru all the rows selected ( if any ), then ges the value of SALES, i.e 75,60 and prints it in the console
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10971265
Be careful to close the while loop ;-)

Your output as per the System.out.println () would be:

75 pounds of Colombian sold this week.
60 pounds of Espresso sold this week.

BTW, you can check the output yourself. What more do you want to ask? If you only want the output of the query explained as per what maheshexp has done, it is more of a database question than a Java question~!

JDBC tutorial - http://java.sun.com/docs/books/tutorial/jdbc/
0
 

Author Comment

by:aquemini001
ID: 10973008
you;re right. sorry. thanks for the help.
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10974100
thanks :-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now