Guest User

Untitled

a guest
Nov 6th, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class MySQLAccess {
  4. private Connection connect = null;
  5. private Statement statement = null;
  6. private PreparedStatement preparedStatement = null;
  7. private ResultSet resultSet = null;
  8.  
  9. public void writeDataBase(Integer ico) throws Exception {
  10. try {
  11. // toto načíta MySQL ovládač, každá DB má vlastný ovládač
  12. Class.forName("com.mysql.jdbc.Driver");
  13.  
  14. // Nastavenie spojenia s DB
  15. connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=8671");
  16. statement = connect.createStatement();
  17.  
  18. preparedStatement = connect.prepareStatement("UPDATE tssu.faktura SET partner = 'áno' WHERE id = ?");
  19.  
  20. // Parameters start with 1
  21. preparedStatement.setInt(1, ico);
  22.  
  23. } catch (Exception e) {
  24. throw e;
  25. } finally {
  26. close();
  27. }
  28.  
  29. }
  30.  
  31. // You need to close the resultSet
  32. private void close() {
  33. try {
  34. if (resultSet != null) {
  35. resultSet.close();
  36. }
  37.  
  38. if (statement != null) {
  39. statement.close();
  40. }
  41.  
  42. if (connect != null) {
  43. connect.close();
  44. }
  45. } catch (Exception e) {
  46.  
  47. }
  48. }
  49.  
  50. }
Add Comment
Please, Sign In to add comment