Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DbConn.java
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import javax.swing.JOptionPane;
- /**
- *
- * @author jlee
- */
- public class DbConn {
- String driver = "com.mysql.jdbc.Driver";
- String url = "jdbc:mysql://localhost/ITDB";
- String user = "root";
- String pass = "abc123";
- Connection conn;
- //Statement stm;
- PreparedStatement stm;
- ResultSet result;
- DbConn(String sql){
- try {
- Class.forName(driver);
- conn = DriverManager.getConnection(url, user, pass);
- //stm = conn.createStatement();
- stm = conn.prepareStatement(sql);
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Warning: " + e.getMessage());
- }
- }
- }
- // Init.java
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package mysql;
- /**
- *
- * @author jlee
- */
- public class Init {
- public static void main(String[] args){
- new MainWin().setVisible(true);
- }
- }
- // Register.java
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package mysql;
- import javax.swing.JOptionPane;
- /**
- *
- * @author jlee
- */
- public class Reg extends javax.swing.JFrame {
- /**
- * Creates new form Reg
- */
- // String driver = "com.mysql.jdbc.Driver";
- // String url = "jdbc:mysql://localhost/ITDB";
- // String user = "root";
- // String pass = "abc123";
- //
- // Connection conn;
- // Statement stm;
- // ResultSet result;
- DbConn dbConn;
- public Reg() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- btSave = new javax.swing.JButton();
- outName = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- inName = new javax.swing.JTextField();
- inEmail = new javax.swing.JTextField();
- btCancel = new javax.swing.JButton();
- btSave.setText("Save");
- btSave.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btSaveActionPerformed(evt);
- }
- });
- outName.setText("Name");
- jLabel2.setText("Email");
- btCancel.setText("Cancel");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(24, 24, 24)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(btSave)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
- .addComponent(btCancel))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(outName)
- .addComponent(jLabel2))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(18, 18, 18)
- .addComponent(inName))
- .addGroup(layout.createSequentialGroup()
- .addGap(20, 20, 20)
- .addComponent(inEmail)))))
- .addGap(25, 25, 25))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(25, 25, 25)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(outName)
- .addComponent(inName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(19, 19, 19)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(inEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btSave)
- .addComponent(btCancel))
- .addContainerGap(29, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void btSaveActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- dbConn = new DbConn("");
- try {
- // Class.forName(driver);
- // conn = DriverManager.getConnection(url, user, pass);
- // stm = conn.createStatement();
- String name = inName.getText();
- String email = inEmail.getText();
- String sql = "insert into ITTB(name, email) values('"+name+"', '"+email+"')";
- dbConn.stm.executeUpdate(sql);
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Warning: " + e.getMessage());
- }
- dispose();
- }
- /**
- * @param args the command line arguments
- */
- // public static void main(String args[]) {
- // /* Set the Nimbus look and feel */
- // //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- // * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- // */
- // try {
- // for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- // if ("Nimbus".equals(info.getName())) {
- // javax.swing.UIManager.setLookAndFeel(info.getClassName());
- // break;
- // }
- // }
- // } catch (ClassNotFoundException ex) {
- // java.util.logging.Logger.getLogger(Reg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- // } catch (InstantiationException ex) {
- // java.util.logging.Logger.getLogger(Reg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- // } catch (IllegalAccessException ex) {
- // java.util.logging.Logger.getLogger(Reg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- // } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- // java.util.logging.Logger.getLogger(Reg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- // }
- // //</editor-fold>
- //
- // /* Create and display the form */
- // java.awt.EventQueue.invokeLater(new Runnable() {
- // public void run() {
- // new Reg().setVisible(true);
- // }
- // });
- // }
- // Variables declaration - do not modify
- private javax.swing.JButton btCancel;
- private javax.swing.JButton btSave;
- private javax.swing.JTextField inEmail;
- private javax.swing.JTextField inName;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel outName;
- // End of variables declaration
- }
- // Upgrade.java
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import javax.swing.JOptionPane;
- /**
- *
- * @author jlee
- */
- public class Upgrade extends javax.swing.JFrame {
- /**
- * Creates new form Upgrade
- */
- // String driver = "com.mysql.jdbc.Driver";
- // String url = "jdbc:mysql://localhost/ITDB";
- // String user = "root";
- // String pass = "abc123";
- //
- // Connection conn;
- // Statement stm;
- // ResultSet result;
- DbConn dbConn;
- String search;
- public Upgrade(String search) {
- this.search = search;
- //dbConn();
- initComponents();
- //outName.setText(search);
- try {
- String sql = "SELECT * FROM ITTB where name = '" + search + "'";
- //PreparedStatement stm = conn.prepareStatement(sSQL);
- //stm = conn.createStatement();
- //ResultSet rs = stm.executeQuery(sql);
- dbConn = new DbConn(sql);
- dbConn.result = dbConn.stm.executeQuery();
- while (dbConn.result.next()) {
- String name = dbConn.result.getString("name");
- String email = dbConn.result.getString("email");
- outName.setText(name);
- outEmail.setText(email);
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, ex);
- }
- //System.out.println(search);
- }
- // void dbConn() {
- // try {
- // Class.forName(driver);
- // conn = DriverManager.getConnection(url, user, pass);
- // stm = conn.createStatement();
- //
- // } catch (Exception e) {
- // JOptionPane.showMessageDialog(null, "Warning: " + e.getMessage());
- // }
- // }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- outName = new javax.swing.JTextField();
- outEmail = new javax.swing.JTextField();
- btUpgrade = new javax.swing.JButton();
- btDelete = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("Name");
- jLabel2.setText("Email");
- btUpgrade.setText("Upgrade");
- btUpgrade.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btUpgradeActionPerformed(evt);
- }
- });
- btDelete.setText("Delete");
- btDelete.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btDeleteActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(49, 49, 49)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addComponent(btUpgrade)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(btDelete))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
- .addComponent(jLabel2))
- .addGap(35, 35, 35)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(outName)
- .addComponent(outEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addContainerGap(58, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(22, 22, 22)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(outName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(outEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btUpgrade)
- .addComponent(btDelete))
- .addContainerGap(27, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void btDeleteActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- try {
- // Class.forName(driver);
- // conn = DriverManager.getConnection(url, user, pass);
- // stm = conn.createStatement();
- String sql = "DELETE FROM ITTB WHERE name = '"+search+"'";
- dbConn = new DbConn(sql);
- dbConn.stm.executeUpdate();
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Warning: " + e.getMessage());
- }
- dispose();
- }
- private void btUpgradeActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- try {
- // Class.forName(driver);
- // conn = DriverManager.getConnection(url, user, pass);
- // stm = conn.createStatement();
- String name = outName.getText();
- String email = outEmail.getText();
- String sql = "UPDATE ITTB SET name = '"+name+"', email= '"+email+"' "
- + "WHERE name = '"+search+"'";
- dbConn = new DbConn(sql);
- dbConn.stm.executeUpdate();
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Warning: " + e.getMessage());
- }
- dispose();
- }
- /**
- * @param args the command line arguments
- */
- // public static void main(String args[]) {
- // /* Set the Nimbus look and feel */
- // //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- // * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- // */
- // try {
- // for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- // if ("Nimbus".equals(info.getName())) {
- // javax.swing.UIManager.setLookAndFeel(info.getClassName());
- // break;
- // }
- // }
- // } catch (ClassNotFoundException ex) {
- // java.util.logging.Logger.getLogger(Upgrade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- // } catch (InstantiationException ex) {
- // java.util.logging.Logger.getLogger(Upgrade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- // } catch (IllegalAccessException ex) {
- // java.util.logging.Logger.getLogger(Upgrade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- // } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- // java.util.logging.Logger.getLogger(Upgrade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- // }
- // //</editor-fold>
- //
- // /* Create and display the form */
- // java.awt.EventQueue.invokeLater(new Runnable() {
- // public void run() {
- // new Upgrade().setVisible(true);
- // }
- // });
- // }
- // Variables declaration - do not modify
- private javax.swing.JButton btDelete;
- private javax.swing.JButton btUpgrade;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JTextField outEmail;
- private javax.swing.JTextField outName;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment