Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. package outfit;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.Statement;
  8.  
  9. public class ToegangsLog {
  10.  
  11. public void main() throws Exception {
  12. ACRReader SERIAL = new ACRReader();
  13. long key = 123;
  14.  
  15. Connection conn = DriverManager.getConnection( "jdbc:mysql://oege.ie.hva.nl/zeverae03", "everae03", "#7HDxm9bf" );
  16. Statement aa = conn.createStatement();
  17. ResultSet AA = aa.executeQuery( "SELECT * FROM `Database` WHERE serial = "+ key +"");
  18. //STAP 1 !!!
  19. if( AA.next() ) {
  20. System.out.println(
  21. "Stap 1: key staat in database");
  22. //STAP 3 !!!
  23. Statement bb = conn.createStatement();
  24. ResultSet BB = bb.executeQuery( "SELECT * FROM `Database` WHERE serial = "+ key +"");
  25. while( BB.next() ) {
  26. int id = BB.getInt( "Toegang" );
  27. //STAP 4 !!!
  28. if ( id == 2){
  29. System.out.println("NOOD PAS, ONTRUIM GEBOUW OMG !!!\nP.S iedereen logd uit ;D");
  30. PreparedStatement GG = conn.prepareStatement("UPDATE `Database` SET `Login` = '0'; ");
  31. GG.executeUpdate();
  32. }
  33. if ( id == 1){
  34. System.out.println("Stap 3: kaarthouder is eigenaar van winkel, DEUR OPEN !!");
  35. }
  36. //STAP 5 !!!
  37. if ( id == 0){
  38. System.out.println("Stap 3: kaarthouder is medewerker ");
  39. Statement cc = conn.createStatement();
  40. ResultSet CC = cc.executeQuery( "SELECT * FROM `Database` WHERE Login = '1'");
  41. if ( CC.next() ) {
  42. System.out.println("Stap 5: er is al iemand ingelogd ");
  43. }
  44. else {
  45. System.out.println("Stap 5: er is niemand ingelogd dus deze kaart logd in, tijd opslaan + deur open ");
  46. PreparedStatement DD = conn.prepareStatement("UPDATE `Database` SET `Login` = '1' WHERE `serial` ="+key +"; ");
  47. DD.executeUpdate();
  48. String intijd = "CURRENT_TIMESTAMP";
  49. PreparedStatement HH = conn.prepareStatement("INSERT INTO `Tijden` ( `serial` , `InTijd` , `UitTijd` )VALUES ("+key+", "+intijd+" , '0000-00-00 00:00:00');");
  50. HH.executeUpdate();
  51.  
  52.  
  53. }
  54. CC.close();
  55. cc.close();
  56. }
  57.  
  58. }
  59. bb.close();
  60. BB.close();
  61.  
  62. }
  63. //STAP 2 !!!
  64. else {
  65. System.out.println("Stap 2: kaart staat niet in de database");
  66. }
  67.  
  68. AA.close();
  69. aa.close();
  70. conn.close();
  71.  
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement