package Employee;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
public class newemp extends javax.swing.JFrame {
Connection con;
Statement stmt;
ResultSet rs;
public newemp() {
initComponents();
DoConnect();
}
public void DoConnect()
{
try
{
String host = "jdbc:derby://localhost:1527/employe";
String uName = "selvan";
String uPass = "selvan";
Connection con = DriverManager.getConnection( host, uName, uPass );
}
catch ( SQLException err )
{
JOptionPane.showMessageDialog(null, err.getMessage());
}
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
empname = new javax.swing.JTextField();
empid = new javax.swing.JTextField();
salary = new javax.swing.JTextField();
occupation = new javax.swing.JTextField();
add = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
jLabel1.setText("Employee Name");
jLabel2.setText("Employee ID");
jLabel3.setText("Salary");
jLabel4.setText("Occupation");
salary.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
salaryActionPerformed(evt);
}
});
add.setText("ADD");
add.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addActionPerformed(evt);
}
});
jButton1.setText("<< Back");
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(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(100, 100, 100)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addComponent(empname)
.addComponent(empid)
.addComponent(salary)
.addComponent(occupation, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
.addGap(136, 136, 136)
.addComponent(add)
.addContainerGap(208, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(24, 24, 24))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(56, 56, 56)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(empname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(empid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(43, 43, 43)
.addComponent(add)))
.addGap(13, 13, 13)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(salary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(45, 45, 45)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(occupation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 100, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(40, 40, 40))
);
pack();
}// </editor-fold>
private void salaryActionPerformed(java.awt.event.ActionEvent evt) {
}
private void addActionPerformed(java.awt.event.ActionEvent evt) {
try
{
stmt = con.createStatement();
String sql = "INSERT INTO SELVAN.WORKERS VALUES ('" +empid.getText()+ "' and '" + empname.getText()+ "' and '" + salary.getText() + "')";
rs = stmt.executeQuery(sql);
String msg;
msg = " "+ empname.getText() + " are added to our company.The emp ID is" + empid.getText();
empid.setText("");
empname.setText("");
salary.setText("");
JOptionPane.showMessageDialog(null,msg);
}
catch (SQLException err)
{
JOptionPane.showMessageDialog(null, err.getMessage());
}
}
public static void main(String args[]) {
//<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 How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClass Name());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(newemp.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(newemp.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(newemp.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(newemp.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new newemp().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton add;
private javax.swing.JTextField empid;
private javax.swing.JTextField empname;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JTextField occupation;
private javax.swing.JTextField salary;
// End of variables declaration
}