Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package debt;
- import java.sql.*;
- import javax.swing.*;
- import java.awt.*;
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- JFrame frame = new JFrame("ButtonDemo");
- frame.setTitle("Five Highest Debts");
- frame.setVisible(true);
- frame.setResizable(false);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Create and set up the content pane.
- JTextArea txtArea = new JTextArea();
- buttonEvent elisten = new buttonEvent(txtArea);
- txtArea.setEditable(false);
- elisten.setOpaque(true); //content panes must be opaque
- frame.setContentPane(elisten);
- //Display the window.
- frame.pack();
- frame.setVisible(true);
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String dbUser = "root";
- String dbPass = "";
- String dbHost = "localhost";
- String dbPort = "3306";
- String dbName = "debtlist";
- String url = "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName;
- Connection con = DriverManager.getConnection(url, dbUser, dbPass);
- System.out.println("Connection established successfully");
- Statement stmt = con.createStatement();
- String query = "SELECT Debt FROM customer ORDER BY Debt DESC";
- ResultSet rs = stmt.executeQuery(query);
- float[] debt;
- debt = new float[5];
- String[] name, surname;
- name = new String[5];
- surname = new String[5];
- int i = 0;
- while (rs.next()) {
- if (i < 5) {
- name[i] = rs.getString("First_Name");
- surname[i] = rs.getString("Surname");
- debt[i] = rs.getFloat("Debt");
- i++;
- }
- }
- stmt.close();
- } catch (ClassNotFoundException e) {
- System.out.println("Driver not found");
- e.printStackTrace(System.out);
- } catch (SQLException ex) {
- System.out.println("ERROR:Connection not established");
- ex.printStackTrace(System.out);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement