Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

What would the code to do this database?

Posted on 2004-05-01
4
Medium Priority
?
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
maheshexp earned 80 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:Mayank S
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

636 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