Advertisement
Guest User

Untitled

a guest
Feb 28th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5. import java.util.ArrayList;
  6. import javax.swing.JOptionPane;
  7. import javax.swing.table.DefaultTableModel;
  8. import sun.security.util.Password;
  9.  
  10.  
  11. public class pass extends javax.swing.JFrame {
  12.  
  13.  
  14. DefaultTableModel model1;
  15. //String query = "SELECT *,PosName from employeetbl inner join positiontbl"+" on employeetbl.PosID=positiontbl.PosID";
  16. String query = "SELECT * from employeetbl";
  17.  
  18. public pass() {
  19.  
  20. initComponents();
  21.  
  22.  
  23. // Connection connection=getConnection();
  24. // String query1 = "SELECT * FROM employeetbl where EmpID='"+idT.getText()+"'";
  25. // Statement st;
  26. // ResultSet rs;
  27. // try {
  28. // st = (Statement) connection.createStatement();
  29. // rs = st.executeQuery(query1);
  30. //
  31. // while(rs.next())
  32. // {
  33. //
  34. // }
  35. //
  36. // } catch (Exception e) {
  37. // e.printStackTrace();
  38. // return;
  39. //
  40. // }
  41. //
  42. }
  43. public void executeSQLQuery (String query)
  44. {
  45. Connection con=getConnection();
  46. Statement st;
  47. try {
  48. st= (Statement) con.createStatement();
  49. if((st.executeUpdate(query))==1)
  50. {
  51.  
  52. }
  53. else {
  54.  
  55. }
  56. } catch(Exception ex) {
  57. ex.printStackTrace();
  58. JOptionPane.showMessageDialog(null, "wrong wrong");
  59. return;
  60. }
  61. }
  62.  
  63. public Connection getConnection()
  64. {
  65. Connection con;
  66. try{
  67. String myDriver = "org.gjt.mm.mysql.Driver";
  68. String myUrl = "jdbc:mysql://localhost/employeeconnect";
  69. Class.forName(myDriver);
  70. con = (Connection) DriverManager.getConnection(myUrl, "root", "");
  71. return con;
  72. }
  73.  
  74. catch (Exception e){
  75. e.printStackTrace();
  76. JOptionPane.showMessageDialog(null,"Error");
  77. return null;
  78.  
  79. }
  80. }
  81. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  82. String EmpID= "SELECT * FROM employeetbl where EmpID=? and Password=?";
  83. String Password=String.valueOf(passT.getPassword());
  84.  
  85. Connection con = getConnection();
  86.  
  87. String query1 = "SELECT * FROM employeetbl where EmpID='"+passidT.getText()+"'";
  88.  
  89. Statement st;
  90. ResultSet rs;
  91.  
  92. try{
  93. st= (Statement) con.createStatement();
  94. rs= st.executeQuery(query1);
  95.  
  96. while(rs.next())
  97. {
  98. EmpID=rs.getString("EmpID");
  99. Password=rs.getString("Password");
  100.  
  101. //JOptionPane.showMessageDialog(null, EmpID+Password);
  102. }
  103.  
  104. if(passidT.getText().equals(EmpID) & Password.equals(Password)){
  105. JOptionPane.showMessageDialog(null, "Welcome!");
  106. mainmenu frame = new mainmenu();
  107. frame.setVisible(true);
  108. }
  109. else if(passidT.getText().isEmpty() && passT.getText().isEmpty()){
  110. JOptionPane.showMessageDialog(null, "Please input sufficient details.");
  111. }
  112.  
  113. else if(passidT.getText().isEmpty()) {
  114. JOptionPane.showMessageDialog(null, "Please input your ID!");
  115. }
  116.  
  117. else if(passT.getText().isEmpty()){
  118. JOptionPane.showMessageDialog(null, "Please input your password!");
  119. }
  120.  
  121. else {
  122. JOptionPane.showMessageDialog(null,"Please input the correct details!");
  123. }
  124. } catch(Exception e) {
  125. JOptionPane.showMessageDialog(null, "a 4th wall breaker, I see..");
  126. return;
  127. }
  128.  
  129.  
  130.  
  131. }
  132.  
  133. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  134. JOptionPane.showMessageDialog(null,"I'll miss you :frowning: ");
  135.  
  136. intro frame = new intro ();
  137. frame.setVisible(true);
  138. this.dispose();
  139.  
  140. public static void main(String args[]) {
  141. java.awt.EventQueue.invokeLater(new Runnable() {
  142. public void run() {
  143. new pass().setVisible(true);
  144. }
  145. });
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement