Guest User

Untitled

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