?
Solved

What would the code to do this database?

Posted on 2004-05-01
4
Medium Priority
?
251 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 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