Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is one from the Starting Out with Java: From Control Structures through Obj

ID: 675106 • Letter: H

Question

Here is one from the Starting Out with Java: From Control Structures through Objects, 5/e, 5th Edition, Gaddis, Tony
4. Unpaid Order Lookup

Write an application that connects to the CoffeeDB database and displays a JList component. The JList component should display a list of customers with unpaid orders. When the user clicks on a customer, the application should display a summary of all the unpaid orders for that customer.

(Gaddis 1107)

Gaddis, Tony. Starting Out with Java: From Control Structures through Objects, 5/e, 5th Edition. Pearson, 02/2012. VitalBook file.

The citation provided is a guideline. Please check each citation for accuracy before use.

Explanation / Answer

First Create Customers table with Fileds.

Name     varchar2(20)
Amount number
Status    varchar2(20) (paid / unpaid)

/* Program for Customers using JList*/
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.DefaultListModel;
import javax.swing.JList;

public class Customers {
    private String name;
    private int Amount;
    private String Status;

    public Customers(String name, int Amount,String Status)
    public String toString(){ return name + " - " + Status; }
}

String query="SELECT * FROM Customers";
DefaultListModel model=new DefaultListModel();
DefaultListModel model1=new DefaultListModel();
try
{                                              Class.forName("oracle.jdbc.driver.OracleDriver");
Statement stmt = null;
ResultSet rs;                                                                        
Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/SPL","username","PWD");
stmt=(Statement) conn.createStatement();
rs=stmt.executeQuery(query);
while (rs.next())
{
String name = rs.getString("name");
String Status = rs.getString("Status");
Customers customers=new Customers(name,Status);
listModel.addElement(customers);
}
JList list=new JList(model);
JList list1=new JList(model1);
f8.add(jpa1);
jpa1.add(list);                              
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);                   
list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
list.setVisibleRowCount(1);
JScrollPane listScroller = new JScrollPane(list);                                        
}
catch(SQLException e)
{
System.out.println("Message   : " + e.getMessage());
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote