Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. public static int createReservation(Rezerwacja rez) {
  2. Connection connect;
  3. Statement statement;
  4. ResultSet resultSet;
  5. boolean b=true;
  6. int id = 0;
  7. int id2 = 5;
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. connect = DriverManager.getConnection("jdbc:mysql://localhost/kino?user=root");
  11. statement=connect.createStatement();
  12. b=statement.execute("INSERT INTO `rezerwacje`(`tytul`, `godzina`, `miejscaZar`, `nazwisko`) VALUES ('"+rez.getTitle()+"', '"+rez.getTime()+"', '"+rez.getTakenSeats()+"', '"+rez.getSurname()+"' );");
  13. if (statement != null) {
  14. statement.close();
  15. }
  16. if (connect != null) {
  17. connect.close();
  18. }
  19. } catch(Exception e) {
  20. e.printStackTrace();
  21. }
  22.  
  23. try {
  24. Class.forName("com.mysql.jdbc.Driver");
  25. connect = DriverManager.getConnection("jdbc:mysql://localhost/kino?user=root");
  26. statement=connect.createStatement();
  27. resultSet = statement.executeQuery("select 'id' from rezerwacje where tytul = '"+rez.getTitle()+"' AND godzina = '"+rez.getTime()+"' AND miejscaZar = '"+rez.getTakenSeats()+"' AND nazwisko = '"+rez.getSurname()+"'");
  28. while (resultSet.next()) {
  29.  
  30. id2 = resultSet.getInt(1);
  31. System.out.println(id2);
  32. }
  33.  
  34. if (resultSet != null) {
  35. resultSet.close();
  36. }
  37. if (statement != null) {
  38. statement.close();
  39. }
  40. if (connect != null) {
  41. connect.close();
  42. }
  43. } catch (Exception e) {
  44. e.printStackTrace();
  45. }
  46. return id2;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement