Guest User

Untitled

a guest
Nov 29th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. import java.sql.*;
  3. /**
  4. *
  5. *
  6. */
  7. public class EMP {
  8.  
  9. /**
  10. * @param args the command line arguments
  11. */
  12. public static void main(String[] args) {
  13.  
  14. PreparedStatement prest;
  15. int count = 0;
  16. String username = "";
  17. String password = "";
  18.  
  19.  
  20. while (count < 5 && (!(username.equals("Brian")) && (!password.equals("Student")))) {
  21.  
  22. username = JOptionPane.showInputDialog(null, "Please Enter your Username ");
  23.  
  24. password = JOptionPane.showInputDialog(null, "Please Enter your Password ");
  25. count++;
  26.  
  27. if (username.equals("Brian") && password.equals("Student")) {
  28. JOptionPane.showMessageDialog(null, " login successfully n Welcome" + username );
  29. break;
  30.  
  31. }
  32.  
  33. if (count >= 5) {
  34. JOptionPane.showMessageDialog(null, "You have used to many attempts n " + "you will not be able to sing in for an hour");
  35. System.exit(0);
  36.  
  37. } else {
  38. 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");
  39.  
  40.  
  41. }
  42. }
  43.  
  44. 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 ");
  45. if (Option.equalsIgnoreCase("A")) {
  46.  
  47. String id = JOptionPane.showInputDialog(null, "Please enter the Employess ID", JOptionPane.QUESTION_MESSAGE);
  48. String fname = JOptionPane.showInputDialog(null, "Please enter Employess First NAME", JOptionPane.QUESTION_MESSAGE);
  49. String sname = JOptionPane.showInputDialog(null, "Please enter Employess Surname NAME", JOptionPane.QUESTION_MESSAGE);
  50. String pss = JOptionPane.showInputDialog(null, "Please enter the Employess PPS Number", JOptionPane.QUESTION_MESSAGE);
  51. String cnum = JOptionPane.showInputDialog(null, "Please ente thr Employess Contact Number", JOptionPane.QUESTION_MESSAGE);
  52. String address = JOptionPane.showInputDialog(null, "Please enter Employess Address", JOptionPane.QUESTION_MESSAGE);
  53. String dep = JOptionPane.showInputDialog(null, "Please enter Employess Deparment ", JOptionPane.QUESTION_MESSAGE);
  54. String sal = JOptionPane.showInputDialog(null, "Please enter Employess salary", JOptionPane.QUESTION_MESSAGE);
  55.  
  56. JOptionPane.showConfirmDialog(null, id + sname + "Records have been entered ");
  57.  
  58. try{
  59.  
  60. String host = "jdbc:derby://localhost/ee ";
  61. String uName = "aa";
  62. String uPass = "bb";
  63. Connection con = DriverManager.getConnection(host, uName, uPass);
  64. //Connection con = DriverManager.getConnection(host);
  65. //Customer Lookup by Last Name
  66.  
  67. //SQL
  68.  
  69. String sql = "INSERT INTO emp (id, fname, sname, pss, cnum, address, dep, sal) VALUES (?,?,?,?,?,?,?,? )";
  70.  
  71. prest = con.prepareStatement(sql);
  72.  
  73. // Variable Customer Name Passes up to SQL as ?
  74. prest.setString(1,id);
  75. prest.setString(2,fname);
  76. prest.setString(3,sname);
  77. prest.setString(4,pss);
  78. prest.setString(5,cnum);
  79. prest.setString(6,address);
  80. prest.setString(7,dep);
  81. prest.setString(8,sal);
  82. prest.executeUpdate();
  83.  
  84.  
  85. }
  86. catch (SQLException err) {
  87.  
  88. System.out.println(err.getMessage());
  89. }
  90.  
  91.  
  92.  
  93. } else if (Option.equalsIgnoreCase("B")) {
  94.  
  95. String id = JOptionPane.showInputDialog(null, "Please enter the Employess ID", JOptionPane.QUESTION_MESSAGE);
  96.  
  97. String fname = JOptionPane.showInputDialog(null, "Please enter Employess First NAME", JOptionPane.QUESTION_MESSAGE);
  98. String sname = JOptionPane.showInputDialog(null, "Please enter Employess Surname NAME", JOptionPane.QUESTION_MESSAGE);
  99. String pss = JOptionPane.showInputDialog(null, "Please enter the Employess PPS Number", JOptionPane.QUESTION_MESSAGE);
  100. String cnum = JOptionPane.showInputDialog(null, "Please ente thr Employess Contact Number", JOptionPane.QUESTION_MESSAGE);
  101. String address = JOptionPane.showInputDialog(null, "Please enter Employess Address", JOptionPane.QUESTION_MESSAGE);
  102. String dep = JOptionPane.showInputDialog(null, "Please enter Employess Deparment ", JOptionPane.QUESTION_MESSAGE);
  103. String sal = JOptionPane.showInputDialog(null, "Please enter Employess salary", JOptionPane.QUESTION_MESSAGE);
  104.  
  105. JOptionPane.showConfirmDialog(null, id + sname + "Records have been entered ");
  106.  
  107. try{
  108.  
  109. String host = "jdbc:derby://localhost/ee ";
  110. String uName = "aa";
  111. String uPass = "bb";
  112. Connection con = DriverManager.getConnection(host, uName, uPass);
  113. //Connection con = DriverManager.getConnection(host);
  114. //Customer Lookup by Last Name
  115.  
  116. //SQL
  117.  
  118. String sql = "UPDATE emp SET fname = [?],sname = [?],pss = [?],cnum = [?],address = [?],dep = [?],sal =[?], where id = [?]";
  119.  
  120.  
  121.  
  122. prest = con.prepareStatement(sql);
  123.  
  124.  
  125. prest.setString(1,id);
  126. prest.setString(2,fname);
  127. prest.setString(3,sname);
  128. prest.setString(4,pss);
  129. prest.setString(5,cnum);
  130. prest.setString(6,address);
  131. prest.setString(7,dep);
  132. prest.setString(8,sal);
  133. prest.executeUpdate();
  134.  
  135.  
  136. }
  137. catch (SQLException err) {
  138.  
  139. System.out.println(err.getMessage());
  140. }
  141. }
  142. }
  143.  
  144. }
Add Comment
Please, Sign In to add comment