Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. private void dodaj_do_bazy() throws SQLException {
  2.  
  3. Pilkarz z = new Pilkarz();
  4. z.setImie(this.pole1.getText());
  5. z.setNazwisko(this.pole2.getText());
  6. z.setKlub(this.pole3.getText());
  7. z.setNarodowosc(this.pole4.getText()); // DODODANIE DO BAZY
  8. z.setPozycja(this.pole5.getText());
  9. z.setNumer(Integer.valueOf(this.pole6.getText()));
  10. z.setWiek(Integer.valueOf(this.pole7.getText()));
  11. z.setData_zakupu(Integer.valueOf(this.pole8.getText()));
  12. Object[] o = new Object[8];
  13. o[0] = z.getImie();
  14. o[3] = z.getNazwisko();
  15. o[1] = z.getKlub();
  16. o[2] = z.getNarodowosc();
  17. o[5] = z.getPozycja();
  18. o[4] = z.getNumer();
  19. o[6] = z.getWiek();
  20. o[7] = z.getData_zakupu();
  21. Connection dbConnection = null;
  22. PreparedStatement preparedStatement = null;
  23. PreparedStatement preparedStatement1 = null;
  24. String SAdd = "INSERT INTO pilkarze VALUES (null,'" + o[0] + "','" + o[1] + "','" + o[2] + "','" + o[3] + "'," + o[4] + ",'" + o[5] + "'," + o[6] + ")";
  25. String SAddx = "INSERT INTO zakup (data) VALUES ('" + o[7] + "')";
  26.  
  27. try {
  28. dbConnection = getDBConnection();
  29. preparedStatement = dbConnection.prepareStatement(SAdd);
  30. preparedStatement1 = dbConnection.prepareStatement(SAddx);
  31. preparedStatement.executeUpdate();
  32. preparedStatement1.executeUpdate();
  33.  
  34. System.out.println("Dodano piłkarza do bazy");
  35. } catch (SQLException e) {
  36. System.out.println(e.getMessage());
  37. } finally {
  38.  
  39. if (preparedStatement != null && preparedStatement != null) {
  40. preparedStatement.close();
  41. preparedStatement1.close();
  42. }
  43.  
  44. if (dbConnection != null) {
  45. dbConnection.close();
  46. }
  47.  
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement