Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- import java.sql.*;
- /**
- *
- *
- */
- public class EMP {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- PreparedStatement prest;
- int count = 0;
- String username = "";
- String password = "";
- while (count < 5 && (!(username.equals("Brian")) && (!password.equals("Student")))) {
- username = JOptionPane.showInputDialog(null, "Please Enter your Username ");
- password = JOptionPane.showInputDialog(null, "Please Enter your Password ");
- count++;
- if (username.equals("Brian") && password.equals("Student")) {
- JOptionPane.showMessageDialog(null, " login successfully n Welcome" + username );
- break;
- }
- if (count >= 5) {
- JOptionPane.showMessageDialog(null, "You have used to many attempts n " + "you will not be able to sing in for an hour");
- System.exit(0);
- } else {
- JOptionPane.showMessageDialog(null, "Wrong username or password n please try again n"+ "you have used " + count + " out of 5 attpemts n before your account will be locked for 1 hour");
- }
- }
- String Option = JOptionPane.showInputDialog(null, "Please enter one of the options n A. Add a new Employee n B. Upate Empoyess record n C. Search Employee name by their id number n D. List All employess n E. Delete Employeen F. Exit System n Your Chosse ");
- if (Option.equalsIgnoreCase("A")) {
- String id = JOptionPane.showInputDialog(null, "Please enter the Employess ID", JOptionPane.QUESTION_MESSAGE);
- String fname = JOptionPane.showInputDialog(null, "Please enter Employess First NAME", JOptionPane.QUESTION_MESSAGE);
- String sname = JOptionPane.showInputDialog(null, "Please enter Employess Surname NAME", JOptionPane.QUESTION_MESSAGE);
- String pss = JOptionPane.showInputDialog(null, "Please enter the Employess PPS Number", JOptionPane.QUESTION_MESSAGE);
- String cnum = JOptionPane.showInputDialog(null, "Please ente thr Employess Contact Number", JOptionPane.QUESTION_MESSAGE);
- String address = JOptionPane.showInputDialog(null, "Please enter Employess Address", JOptionPane.QUESTION_MESSAGE);
- String dep = JOptionPane.showInputDialog(null, "Please enter Employess Deparment ", JOptionPane.QUESTION_MESSAGE);
- String sal = JOptionPane.showInputDialog(null, "Please enter Employess salary", JOptionPane.QUESTION_MESSAGE);
- JOptionPane.showConfirmDialog(null, id + sname + "Records have been entered ");
- try{
- String host = "jdbc:derby://localhost/ee ";
- String uName = "aa";
- String uPass = "bb";
- Connection con = DriverManager.getConnection(host, uName, uPass);
- //Connection con = DriverManager.getConnection(host);
- //Customer Lookup by Last Name
- //SQL
- String sql = "INSERT INTO emp (id, fname, sname, pss, cnum, address, dep, sal) VALUES (?,?,?,?,?,?,?,? )";
- prest = con.prepareStatement(sql);
- // Variable Customer Name Passes up to SQL as ?
- prest.setString(1,id);
- prest.setString(2,fname);
- prest.setString(3,sname);
- prest.setString(4,pss);
- prest.setString(5,cnum);
- prest.setString(6,address);
- prest.setString(7,dep);
- prest.setString(8,sal);
- prest.executeUpdate();
- }
- catch (SQLException err) {
- System.out.println(err.getMessage());
- }
- } else if (Option.equalsIgnoreCase("B")) {
- String id = JOptionPane.showInputDialog(null, "Please enter the Employess ID", JOptionPane.QUESTION_MESSAGE);
- String fname = JOptionPane.showInputDialog(null, "Please enter Employess First NAME", JOptionPane.QUESTION_MESSAGE);
- String sname = JOptionPane.showInputDialog(null, "Please enter Employess Surname NAME", JOptionPane.QUESTION_MESSAGE);
- String pss = JOptionPane.showInputDialog(null, "Please enter the Employess PPS Number", JOptionPane.QUESTION_MESSAGE);
- String cnum = JOptionPane.showInputDialog(null, "Please ente thr Employess Contact Number", JOptionPane.QUESTION_MESSAGE);
- String address = JOptionPane.showInputDialog(null, "Please enter Employess Address", JOptionPane.QUESTION_MESSAGE);
- String dep = JOptionPane.showInputDialog(null, "Please enter Employess Deparment ", JOptionPane.QUESTION_MESSAGE);
- String sal = JOptionPane.showInputDialog(null, "Please enter Employess salary", JOptionPane.QUESTION_MESSAGE);
- JOptionPane.showConfirmDialog(null, id + sname + "Records have been entered ");
- try{
- String host = "jdbc:derby://localhost/ee ";
- String uName = "aa";
- String uPass = "bb";
- Connection con = DriverManager.getConnection(host, uName, uPass);
- //Connection con = DriverManager.getConnection(host);
- //Customer Lookup by Last Name
- //SQL
- String sql = "UPDATE emp SET fname = [?],sname = [?],pss = [?],cnum = [?],address = [?],dep = [?],sal =[?], where id = [?]";
- prest = con.prepareStatement(sql);
- prest.setString(1,id);
- prest.setString(2,fname);
- prest.setString(3,sname);
- prest.setString(4,pss);
- prest.setString(5,cnum);
- prest.setString(6,address);
- prest.setString(7,dep);
- prest.setString(8,sal);
- prest.executeUpdate();
- }
- catch (SQLException err) {
- System.out.println(err.getMessage());
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment