Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 23.76 KB | None | 0 0
  1.  
  2. /*
  3.  * Players.java
  4.  *
  5.  * Created on Apr 19, 2011, 12:55:43 PM
  6.  */
  7.  
  8. package Users;
  9.  
  10. import java.sql.Connection;
  11. import java.sql.DriverManager;
  12. import java.sql.SQLException;
  13. import java.sql.Statement;
  14. import java.sql.ResultSet;
  15. import javax.swing.JOptionPane;
  16.  
  17. public class Players extends javax.swing.JFrame {
  18.  
  19.     Connection con;
  20.     Statement stmt;
  21.     ResultSet rs;
  22.     int currentRow = 0;
  23.  
  24.     /** Creates new form Players */
  25.     public Players() {
  26.         initComponents();
  27.         DoConnect();
  28.     }
  29.  
  30.     public void DoConnect() {
  31.  
  32.         try {
  33.             //Connect to the Database
  34.  
  35.             String host = "jdbc:derby://localhost:1527/Players1";
  36.             String userName = "user";
  37.             String userPassword = "henry";
  38.             con = DriverManager.getConnection(host, userName, userPassword);
  39.            
  40.             // Execute SQL and loads data
  41.             stmt = con.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
  42.             String sql = "SELECT * FROM APP.PLAYERS";
  43.             rs = stmt.executeQuery(sql);
  44.  
  45.  
  46.  
  47.             // Looking through data
  48.  
  49.             rs.next();
  50.             int id_col = rs.getInt("ID");
  51.             String id = Integer.toString(id_col);
  52.             String first = rs.getString("FIRST_NAME");
  53.             String last = rs.getString("Last_Name");
  54.             String type = rs.getString("User_Type");
  55.  
  56.             // Display records
  57.  
  58.             textID.setText(id);
  59.             textFirstName.setText(first);
  60.             textLastName.setText(last);
  61.             textUserType.setText(type);
  62.  
  63.         }
  64.  
  65.         catch (SQLException err) {
  66.             JOptionPane.showMessageDialog(Players.this, err.getMessage());
  67.  
  68.         }
  69.  
  70.     }
  71.  
  72.    
  73.     @SuppressWarnings("unchecked")
  74.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  75.     private void initComponents() {
  76.  
  77.         jPanel1 = new javax.swing.JPanel();
  78.         textID = new javax.swing.JTextField();
  79.         textFirstName = new javax.swing.JTextField();
  80.         textLastName = new javax.swing.JTextField();
  81.         jLabel1 = new javax.swing.JLabel();
  82.         textUserType = new javax.swing.JTextField();
  83.         jPanel2 = new javax.swing.JPanel();
  84.         btnNext = new javax.swing.JButton();
  85.         btnPrevious = new javax.swing.JButton();
  86.         btnFirst = new javax.swing.JButton();
  87.         btnLast = new javax.swing.JButton();
  88.         jPanel3 = new javax.swing.JPanel();
  89.         btnUpdateRecord = new javax.swing.JButton();
  90.         btnDeleteRecord = new javax.swing.JButton();
  91.         btnNewRecord = new javax.swing.JButton();
  92.         btnSaveRecord = new javax.swing.JButton();
  93.         btnCancelRecord = new javax.swing.JButton();
  94.  
  95.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  96.  
  97.         textID.setText("textID");
  98.         textID.addActionListener(new java.awt.event.ActionListener() {
  99.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  100.                 textIDActionPerformed(evt);
  101.             }
  102.         });
  103.  
  104.         textFirstName.setText("textFirstName");
  105.  
  106.         textLastName.setText("textLastName");
  107.  
  108.         jLabel1.setText("User Type");
  109.  
  110.         textUserType.setText("textUserType");
  111.         textUserType.addActionListener(new java.awt.event.ActionListener() {
  112.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  113.                 textUserTypeActionPerformed(evt);
  114.             }
  115.         });
  116.  
  117.         org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
  118.         jPanel1.setLayout(jPanel1Layout);
  119.         jPanel1Layout.setHorizontalGroup(
  120.             jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  121.             .add(jPanel1Layout.createSequentialGroup()
  122.                 .addContainerGap()
  123.                 .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  124.                     .add(jPanel1Layout.createSequentialGroup()
  125.                         .add(textID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  126.                         .add(31, 31, 31)
  127.                         .add(textFirstName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  128.                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
  129.                         .add(textLastName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
  130.                     .add(jPanel1Layout.createSequentialGroup()
  131.                         .add(jLabel1)
  132.                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  133.                         .add(textUserType, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)))
  134.                 .addContainerGap())
  135.         );
  136.         jPanel1Layout.setVerticalGroup(
  137.             jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  138.             .add(jPanel1Layout.createSequentialGroup()
  139.                 .addContainerGap()
  140.                 .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
  141.                     .add(textFirstName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  142.                     .add(textLastName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  143.                     .add(textID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
  144.                 .add(18, 18, 18)
  145.                 .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
  146.                     .add(textUserType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  147.                     .add(jLabel1))
  148.                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  149.         );
  150.  
  151.         btnNext.setText("Next");
  152.         btnNext.addActionListener(new java.awt.event.ActionListener() {
  153.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  154.                 btnNextActionPerformed(evt);
  155.             }
  156.         });
  157.  
  158.         btnPrevious.setText("Previous");
  159.         btnPrevious.addActionListener(new java.awt.event.ActionListener() {
  160.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  161.                 btnPreviousActionPerformed(evt);
  162.             }
  163.         });
  164.  
  165.         btnFirst.setText("First");
  166.         btnFirst.addActionListener(new java.awt.event.ActionListener() {
  167.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  168.                 btnFirstActionPerformed(evt);
  169.             }
  170.         });
  171.  
  172.         btnLast.setText("Last");
  173.         btnLast.addActionListener(new java.awt.event.ActionListener() {
  174.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  175.                 btnLastActionPerformed(evt);
  176.             }
  177.         });
  178.  
  179.         org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
  180.         jPanel2.setLayout(jPanel2Layout);
  181.         jPanel2Layout.setHorizontalGroup(
  182.             jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  183.             .add(jPanel2Layout.createSequentialGroup()
  184.                 .add(btnNext)
  185.                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  186.                 .add(btnPrevious)
  187.                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  188.                 .add(btnFirst)
  189.                 .add(18, 18, 18)
  190.                 .add(btnLast)
  191.                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  192.         );
  193.         jPanel2Layout.setVerticalGroup(
  194.             jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  195.             .add(jPanel2Layout.createSequentialGroup()
  196.                 .addContainerGap()
  197.                 .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
  198.                     .add(btnNext)
  199.                     .add(btnPrevious)
  200.                     .add(btnFirst)
  201.                     .add(btnLast))
  202.                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  203.         );
  204.  
  205.         btnUpdateRecord.setText("Update");
  206.         btnUpdateRecord.addActionListener(new java.awt.event.ActionListener() {
  207.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  208.                 btnUpdateRecordActionPerformed(evt);
  209.             }
  210.         });
  211.  
  212.         btnDeleteRecord.setText("Delete");
  213.         btnDeleteRecord.addActionListener(new java.awt.event.ActionListener() {
  214.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  215.                 btnDeleteRecordActionPerformed(evt);
  216.             }
  217.         });
  218.  
  219.         btnNewRecord.setText("New");
  220.         btnNewRecord.addActionListener(new java.awt.event.ActionListener() {
  221.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  222.                 btnNewRecordActionPerformed(evt);
  223.             }
  224.         });
  225.  
  226.         btnSaveRecord.setText("Save Record");
  227.         btnSaveRecord.setEnabled(false);
  228.         btnSaveRecord.addActionListener(new java.awt.event.ActionListener() {
  229.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  230.                 btnSaveRecordActionPerformed(evt);
  231.             }
  232.         });
  233.  
  234.         btnCancelRecord.setText("Cancel Record");
  235.         btnCancelRecord.setEnabled(false);
  236.         btnCancelRecord.addActionListener(new java.awt.event.ActionListener() {
  237.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  238.                 btnCancelRecordActionPerformed(evt);
  239.             }
  240.         });
  241.  
  242.         org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
  243.         jPanel3.setLayout(jPanel3Layout);
  244.         jPanel3Layout.setHorizontalGroup(
  245.             jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  246.             .add(jPanel3Layout.createSequentialGroup()
  247.                 .addContainerGap()
  248.                 .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  249.                     .add(jPanel3Layout.createSequentialGroup()
  250.                         .add(btnUpdateRecord)
  251.                         .add(30, 30, 30)
  252.                         .add(btnDeleteRecord)
  253.                         .add(31, 31, 31)
  254.                         .add(btnNewRecord)
  255.                         .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  256.                     .add(jPanel3Layout.createSequentialGroup()
  257.                         .add(btnSaveRecord)
  258.                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 43, Short.MAX_VALUE)
  259.                         .add(btnCancelRecord)
  260.                         .add(30, 30, 30))))
  261.         );
  262.         jPanel3Layout.setVerticalGroup(
  263.             jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  264.             .add(jPanel3Layout.createSequentialGroup()
  265.                 .add(9, 9, 9)
  266.                 .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
  267.                     .add(btnNewRecord)
  268.                     .add(btnDeleteRecord)
  269.                     .add(btnUpdateRecord))
  270.                 .add(18, 18, 18)
  271.                 .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
  272.                     .add(btnSaveRecord)
  273.                     .add(btnCancelRecord))
  274.                 .addContainerGap(27, Short.MAX_VALUE))
  275.         );
  276.  
  277.         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
  278.         getContentPane().setLayout(layout);
  279.         layout.setHorizontalGroup(
  280.             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  281.             .add(layout.createSequentialGroup()
  282.                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  283.                     .add(layout.createSequentialGroup()
  284.                         .addContainerGap()
  285.                         .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  286.                     .add(layout.createSequentialGroup()
  287.                         .add(11, 11, 11)
  288.                         .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  289.                     .add(layout.createSequentialGroup()
  290.                         .addContainerGap()
  291.                         .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
  292.                 .addContainerGap())
  293.         );
  294.         layout.setVerticalGroup(
  295.             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  296.             .add(layout.createSequentialGroup()
  297.                 .addContainerGap()
  298.                 .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  299.                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  300.                 .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  301.                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  302.                 .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  303.                 .addContainerGap())
  304.         );
  305.  
  306.         pack();
  307.     }// </editor-fold>
  308.  
  309.     private void textIDActionPerformed(java.awt.event.ActionEvent evt) {
  310.         // TODO add your handling code here:
  311.     }
  312.  
  313.     private void textUserTypeActionPerformed(java.awt.event.ActionEvent evt) {
  314.         // TODO add your handling code here:
  315.     }
  316.  
  317.     private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {
  318.         try {
  319.             if (rs.next()) {
  320.  
  321.                 int id_col = rs.getInt("ID");
  322.                 String id = Integer.toString(id_col);
  323.                 String first = rs.getString("First_Name");
  324.                 String last = rs.getString("Last_Name");
  325.                 String user = rs.getString("User_Type");
  326.  
  327.                 textID.setText(id);
  328.                 textFirstName.setText(first);
  329.                 textLastName.setText(last);
  330.                 textUserType.setText(user);
  331.  
  332.             }
  333.  
  334.             else {
  335.                 rs.previous();
  336.                 JOptionPane.showMessageDialog(Players.this, "End Of File");
  337.  
  338.             }
  339.         }
  340.         catch (SQLException err) {
  341.             JOptionPane.showMessageDialog(Players.this, err.getMessage());
  342.         }
  343.     }
  344.  
  345.     private void btnPreviousActionPerformed(java.awt.event.ActionEvent evt) {
  346.        try {
  347.             if (rs.previous()) {
  348.  
  349.                 int id_col = rs.getInt("ID");
  350.                 String id = Integer.toString(id_col);
  351.                 String first = rs.getString("First_Name");
  352.                 String last = rs.getString("Last_Name");
  353.                 String user = rs.getString("User_Type");
  354.  
  355.                 textID.setText(id);
  356.                 textFirstName.setText(first);
  357.                 textLastName.setText(last);
  358.                 textUserType.setText(user);
  359.  
  360.             }
  361.  
  362.             else {
  363.                 rs.next();
  364.                 JOptionPane.showMessageDialog(Players.this, "Start of File");
  365.  
  366.             }
  367.         }
  368.         catch (SQLException err) {
  369.             JOptionPane.showMessageDialog(Players.this, err.getMessage());
  370.         }
  371.     }
  372.  
  373.     private void btnFirstActionPerformed(java.awt.event.ActionEvent evt) {
  374.         try {
  375.                 rs.first();
  376.                 int id_col = rs.getInt("ID");
  377.                 String id = Integer.toString(id_col);
  378.                 String first = rs.getString("First_Name");
  379.                 String last = rs.getString("Last_Name");
  380.                 String user = rs.getString("User_Type");
  381.  
  382.                 textID.setText(id);
  383.                 textFirstName.setText(first);
  384.                 textLastName.setText(last);
  385.                 textUserType.setText(user);
  386.         }
  387.         catch (SQLException err) {
  388.             JOptionPane.showMessageDialog(Players.this, err.getMessage());
  389.         }
  390.     }
  391.  
  392.     private void btnLastActionPerformed(java.awt.event.ActionEvent evt) {
  393.          try {
  394.                 rs.last();
  395.                 int id_col = rs.getInt("ID");
  396.                 String id = Integer.toString(id_col);
  397.                 String first = rs.getString("First_Name");
  398.                 String last = rs.getString("Last_Name");
  399.                 String user = rs.getString("User_Type");
  400.  
  401.                 textID.setText(id);
  402.                 textFirstName.setText(first);
  403.                 textLastName.setText(last);
  404.                 textUserType.setText(user);
  405.         }
  406.         catch (SQLException err) {
  407.             JOptionPane.showMessageDialog(Players.this, err.getMessage());
  408.         }
  409.     }
  410.  
  411.     private void btnUpdateRecordActionPerformed(java.awt.event.ActionEvent evt) {
  412.         String first = textFirstName.getText( );
  413.         String last = textLastName.getText( );
  414.         String user = textUserType.getText( );
  415.         String ID = textID.getText( );
  416.  
  417.         int newID = Integer.parseInt( ID );
  418.  
  419.         try {
  420.             rs.updateInt( "ID", newID );
  421.             rs.updateString( "First_Name", first );
  422.             rs.updateString( "last_Name", last );
  423.             rs.updateString( "User_Type", user );
  424.             rs.updateRow( );
  425.             JOptionPane.showMessageDialog(Players.this, "Updated");
  426.             }
  427.        
  428.             catch (SQLException err) {
  429.             System.out.println(err.getMessage() );
  430.             }
  431.     }
  432.  
  433.     private void btnNewRecordActionPerformed(java.awt.event.ActionEvent evt) {
  434.  
  435.         try {
  436.  
  437.         currentRow = rs.getRow( );
  438.  
  439.         textFirstName.setText("");
  440.         textLastName.setText("");
  441.         textUserType.setText("");
  442.         textID.setText("");
  443.  
  444.  
  445.         // Hide and show certain buttons
  446.         btnFirst.setEnabled( false );
  447.         btnPrevious.setEnabled( false ) ;
  448.         btnNext.setEnabled( false );
  449.         btnLast.setEnabled( false );
  450.         btnUpdateRecord.setEnabled( false );
  451.         btnDeleteRecord.setEnabled( false );
  452.         btnNewRecord.setEnabled( false );
  453.  
  454.         btnSaveRecord.setEnabled( true );
  455.         btnCancelRecord.setEnabled( true );
  456.         }
  457.  
  458.         catch (SQLException err) {
  459.             System.out.println(err.getMessage() );
  460.         }
  461.  
  462.     }
  463.  
  464.     private void btnCancelRecordActionPerformed(java.awt.event.ActionEvent evt) {
  465.  
  466.        try {
  467.         rs.absolute( currentRow );
  468.  
  469.         textFirstName.setText( rs.getString("First_Name") );
  470.         textLastName.setText( rs.getString("Last_Name") );
  471.         textUserType.setText( rs.getString("User_Type") );
  472.         textID.setText( Integer.toString( rs.getInt("ID" )) );
  473.         // Show certain buttons
  474.  
  475.         btnFirst.setEnabled( true );
  476.         btnPrevious.setEnabled( true ) ;
  477.         btnNext.setEnabled( true );
  478.         btnLast.setEnabled( true );
  479.         btnUpdateRecord.setEnabled( true );
  480.         btnDeleteRecord.setEnabled( true );
  481.         btnNewRecord.setEnabled( true );
  482.  
  483.         btnSaveRecord.setEnabled( false );
  484.         btnCancelRecord.setEnabled( false );
  485.     }
  486.  catch (SQLException err) {
  487.             System.out.println(err.getMessage() );
  488.         }
  489.     }
  490.        private void btnSaveRecordActionPerformed(java.awt.event.ActionEvent evt) {
  491.         String first = textFirstName.getText( );
  492.         String last = textLastName.getText( );
  493.         String user = textUserType.getText( );
  494.         String ID = textID.getText( );
  495.  
  496.         int newID = Integer.parseInt( ID );
  497.  
  498.         try {
  499.             rs.moveToInsertRow();
  500.  
  501.             rs.updateInt("ID", newID);
  502.             rs.updateString( "First_Name", first );
  503.             rs.updateString( "last_Name", last );
  504.             rs.updateString( "User_Type", user );
  505.  
  506.             rs.insertRow();
  507.  
  508.             stmt.close();
  509.             rs.close();
  510.  
  511.             stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
  512.  
  513.             String sql = "SELECT * FROM PLAYERS";
  514.             rs = stmt.executeQuery(sql);
  515.  
  516.             rs.next();
  517.             int id_col = rs.getInt("ID");
  518.             String id = Integer.toString(id_col);
  519.             String first2 = rs.getString("First_Name");
  520.             String last2 = rs.getString("Last_Name");
  521.             String user2 = rs.getString("User_Type");
  522.  
  523.             textID.setText(id);
  524.             textFirstName.setText(first2);
  525.             textLastName.setText(last2);
  526.             textUserType.setText(user2);
  527.  
  528.             btnFirst.setEnabled( true );
  529.             btnPrevious.setEnabled( true ) ;
  530.             btnNext.setEnabled( true );
  531.             btnLast.setEnabled( true );
  532.             btnUpdateRecord.setEnabled( true );
  533.             btnDeleteRecord.setEnabled( true );
  534.             btnNewRecord.setEnabled( true );
  535.  
  536.             btnSaveRecord.setEnabled( false );
  537.             btnCancelRecord.setEnabled( false );
  538.         }
  539.             catch (SQLException err) {
  540.             System.out.println(err.getMessage() );
  541.  
  542.         }
  543.        }
  544.  
  545.        private void btnDeleteRecordActionPerformed(java.awt.event.ActionEvent evt) {
  546.           try {
  547.           rs.deleteRow();
  548.           stmt.close();
  549.           rs.close();
  550.           stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
  551.           String sql = "SELECT * FROM PLAYERS";
  552.           rs = stmt.executeQuery(sql);
  553.  
  554.           rs.next();
  555.           int id_col = rs.getInt("ID");
  556.                 String id = Integer.toString(id_col);
  557.                 String first = rs.getString("First_Name");
  558.                 String last = rs.getString("Last_Name");
  559.                 String user = rs.getString("User_Type");
  560.  
  561.                 textID.setText(id);
  562.                 textFirstName.setText(first);
  563.                 textLastName.setText(last);
  564.                 textUserType.setText(user);
  565.            }
  566.           catch (SQLException err) {
  567.             System.out.println(err.getMessage() );
  568.  
  569.         }
  570.        
  571.        }
  572.    
  573.    
  574.  
  575.     /**
  576.     * @param args the command line arguments
  577.     */
  578.     public static void main(String args[]) {
  579.         java.awt.EventQueue.invokeLater(new Runnable() {
  580.             public void run() {
  581.                 new Players().setVisible(true);
  582.             }
  583.         });
  584.     }
  585.  
  586.     // Variables declaration - do not modify
  587.     private javax.swing.JButton btnCancelRecord;
  588.     private javax.swing.JButton btnDeleteRecord;
  589.     private javax.swing.JButton btnFirst;
  590.     private javax.swing.JButton btnLast;
  591.     private javax.swing.JButton btnNewRecord;
  592.     private javax.swing.JButton btnNext;
  593.     private javax.swing.JButton btnPrevious;
  594.     private javax.swing.JButton btnSaveRecord;
  595.     private javax.swing.JButton btnUpdateRecord;
  596.     private javax.swing.JLabel jLabel1;
  597.     private javax.swing.JPanel jPanel1;
  598.     private javax.swing.JPanel jPanel2;
  599.     private javax.swing.JPanel jPanel3;
  600.     private javax.swing.JTextField textFirstName;
  601.     private javax.swing.JTextField textID;
  602.     private javax.swing.JTextField textLastName;
  603.     private javax.swing.JTextField textUserType;
  604.     // End of variables declaration
  605.  
  606. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement