daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Apr 27th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Employee database query application
  2. import java.sql.SQLException;
  3. import java.sql.Connection;
  4. import java.sql.Statement;
  5. import java.awt.FlowLayout;
  6. import java.awt.BorderLayout;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.WindowAdapter;
  10. import java.awt.event.WindowEvent;
  11. import javax.swing.JFrame;
  12. import javax.swing.JTable;
  13. import javax.swing.JComboBox;
  14. import javax.swing.JButton;
  15. import javax.swing.JTextField;
  16.  
  17. public class DisplayQueryResults extends Jframe
  18. {
  19.      // JDBC driver name and database URL
  20.    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
  21.    static final String DB_URL = "jdbc:mysql://localhost/EMP";
  22.    static final String USER = "username";
  23.    static final String PASS = "password";
  24.    
  25.     //default query retrieve all data from employees table
  26.     static final String Default_Query = "SELECT * FROM employees";
  27.    
  28.     private Connection connection;
  29.     private Statement statement;
  30.     private ResultSetTableModel tablemodel;
  31.     private JTable table;
  32.     private JComboBox inputQuery;
  33.     private JButton submitQuery;
  34.     private JTextField input;
  35.    
  36.     public DisplayQueryResults ()
  37.     {
  38.     super ( "Select Query. Click Submit To See Results.");
  39.     // Create ResultSetTableModel with default JDBC driver,
  40.     //database URL and query
  41.     try
  42.     {
  43.         //create TableModel for results of query SELECT*FROM employees
  44.         tableModel = new ResultSetTableModel ( JDBC Driver, DataBase URL,
  45.         USERNAME, PASSWORD, Default_Query );
  46.        
  47.         connection = tableModel.getConnection();
  48.         {//end try
  49.        
  50.         String Queries [] ={ "Select all employees working in Department " +
  51.         "Sales", "Select hourly employees working over 30 hours.",
  52.         "Select all comission employees in descending order of the " +
  53.         "comission rate.", "Specify particular query"};
  54.        
  55.         public class PayrollSystemTest
  56.    {
  57.       public static void main( String args[] )
  58.       {
  59.          // create subclass objects
  60.          SalariedEmployee salariedEmployee =
  61.            new SalariedEmployee( "Kerry", "Smith", "111-11-1111",
  62.                        800.00 );
  63.         HourlyEmployee hourlyEmployee =
  64.            new HourlyEmployee( "Mike", "Price", "222-22-2222", 16.75,
  65.                        40 );
  66.         CommissionEmployee commissionEmployee =
  67.            new CommissionEmployee(
  68.          "Mark", "Jones", "333-33-3333", 10000, .06 );
  69.         BasePlusCommissionEmployee basePlusCommissionEmployee =
  70.            new BasePlusCommissionEmployee(
  71.            "Bob", "Williams", "444-44-4444", 5000, .04, 300 );
  72.  
  73.         System.out.println( "Employees processed individually:\n" );
  74.  
  75.         System.out.printf( "%s\n%s: $%,.2f\n\n",
  76.            salariedEmployee, "earned", salariedEmployee.earnings() );
  77.         System.out.printf( "%s\n%s: $%,.2f\n\n",
  78.            hourlyEmployee, "earned", hourlyEmployee.earnings() );
  79.         System.out.printf( "%s\n%s: $%,.2f\n\n",
  80.            commissionEmployee, "earned",
  81.                        commissionEmployee.earnings() );
  82.         System.out.printf( "%s\n%s: $%,.2f\n\n",
  83.            basePlusCommissionEmployee,
  84.            "earned", basePlusCommissionEmployee.earnings() );
  85.  
  86.         // create four-element Employee array
  87.  
  88.         Employee employees[] = new Employee[ 4 ];
  89.  
  90.         // initialize array with Employees
  91.         employees[ 0 ] = salariedEmployee;
  92.         employees[ 1 ] = hourlyEmployee;
  93.         employees[ 2 ] = commissionEmployee;
  94.         employees[ 3 ] = basePlusCommissionEmployee;
  95.  
  96.         System.out.println(
  97.                         "Employees processed polymorphically:\n" );
  98.  
  99.         // generically process each element in array employees
  100.         for ( Employee currentEmployee : employees )
  101.         {
  102.            System.out.println( currentEmployee ); // invokes toString
  103.  
  104.  
  105.            // determine whether element is a BasePlusCommissionEmployee
  106.            if (
  107.                            currentEmployee instanceof BasePlusCommissionEmployee )
  108.            {
  109.               // downcast Employee reference to
  110.               // BasePlusCommissionEmployee reference
  111.  
  112.               BasePlusCommissionEmployee employee =
  113.                  ( BasePlusCommissionEmployee ) currentEmployee;
  114.  
  115.               double oldBaseSalary = employee.getBaseSalary();
  116.               employee.setBaseSalary( 1.10 * oldBaseSalary );
  117.               System.out.printf(
  118.                  "new base salary with 10%% increase is: $%,.2f\n",
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top