Access Millions of academic & study documents

4 Suppose you have an SQl database calles sales data with a table c

Content type
User Generated
Showing Page:
1/2
4.Suppose you have an SQl database calles sales _data
with a table customers containing the fields
CustomerID,LastName,FirstName
,city,state,Address,PhoneNumber, and Total Amount
Purchased as well as a large number of records.Suppose
that you have already successfully created a valid
Connection object conn to this database .Write a short
piece of code that prompts the user to input the name of a
state and consequently excutes an SQL query to find all
customers that live in the state specified by the user
.Include some instructions to loop through the results and
print only the last names of these customers as well as the
city names in which they live.
Solution
Statement stmt = con.createStatement();
Scanner sc=new Scanner(System.in);
System.out.println(\"enter the state name\");
String st=sc.NextInt();
String query = \"select * from customer where
state=\'\"+st+\"\'\";
boolean status = stmt.execute(query);
if(status){
ResultSet rs = stmt.getResultSet();

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/2

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
4.Suppose you have an SQl database calles sales _data with a table customers containing the fields CustomerID,LastName,FirstName ,city,state,Address,PhoneNumber, and Total Amount Purchased as well as a large number of records.Suppose that you have already successfully created a valid Connection object conn to this database .Write a short piece of code that prompts the user to input the name of a state and consequently excutes an SQL query to find all customers that live in the state specified by the user .Include some instructions to loop through the results and print only the last names of th ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4