Solved

What would the code to do this database?

Posted on 2004-05-01
4
240 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 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: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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle SQL syntax check  without executing 6 108
ejb on wildfly 5 47
Java: The Public Class Main 4 45
printf performancy 11 86
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 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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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 …

726 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