Professional Documents
Culture Documents
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this
template
*/
package employee3;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
*
* @author Administrator
*/
public class Emp3 extends javax.swing.JFrame {
/**
* Creates new form Emp3
*/
public Emp3() {
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">
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setPreferredSize(new java.awt.Dimension(400, 340));
jLabel2.setText("FNAME");
jLabel3.setText("LNAME");
jLabel4.setText("Salary");
jLabel5.setText("DEPARTMENT");
jLabel6.setText("GENDER");
jRadioButton1.setText("Male");
jRadioButton2.setText("Female");
jTextField3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField3ActionPerformed(evt);
}
});
jLabel7.setText("ID");
jButton1.setText("ADD");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("update");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Delete");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
pack();
}// </editor-fold>
try {
// TODO add your handling code here:
String FName=jTextField1.getText();
String Lname=jTextField5.getText();
String Departement=jTextField2.getText();
String Salary=jTextField3.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/emp","root","");
PreparedStatement Ps=con.prepareStatement("insert into reg
(FName,Lname,Departement,Salary,Gender)values(?,?,?,?,?)");
Ps.setString(1,FName);
Ps.setString(2,Lname);
Ps.setString(3,Departement);
Ps.setString(4,Salary);
if(jRadioButton2.isSelected())
{
Ps.setString(3, jRadioButton2.getText());
}
else
Ps.setString(3, jRadioButton1.getText());
Ps.executeUpdate();
JOptionPane.showMessageDialog(this, "insertion is secucessfully");
/**
* @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(Emp3.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Emp3.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Emp3.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Emp3.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
}
//</editor-fold>