Advertisement
Guest User

Untitled

a guest
Feb 1st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. package de.verkehrszeichen.lobbysystem.sql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. public class SQL {
  9.  
  10. private Connection con;
  11.  
  12. public SQL(String hostname, int port, String username, String password, String database) {
  13. try {
  14. con = DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/" + database + "?autoReconnect=true", username,
  15. password);
  16. } catch (SQLException ex) {
  17. ex.printStackTrace();
  18. }
  19. }
  20.  
  21. public void update(String sql) {
  22. try {
  23. con.prepareStatement(sql).executeUpdate();
  24. } catch (SQLException ex) {
  25. ex.printStackTrace();
  26. }
  27. }
  28.  
  29. public ResultSet query(String sql) {
  30. try {
  31. return con.prepareStatement(sql).executeQuery();
  32. } catch (SQLException ex) {
  33. ex.printStackTrace();
  34. return null;
  35. }
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement