Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. package ?;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7.  
  8. public class AsyncMySQL {
  9. private Connection conn;
  10. private String database;
  11. private String host;
  12. private String passwort;
  13. private String port;
  14. private String user;
  15.  
  16. public AsyncMySQL(String host, String port, String user, String passwort, String database) {
  17. this.host = host;
  18. this.port = port;
  19. this.user = user;
  20. this.passwort = passwort;
  21. this.database = database;
  22. }
  23.  
  24. public Connection getConnection() {
  25. try {
  26. if (this.conn == null || this.conn.isClosed()) {
  27. this.conn = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.user, this.passwort);
  28. System.out.println("Also die Verbindung ist schon mal da.");
  29. }
  30. } catch (Exception ex) {
  31. ex.printStackTrace();
  32. }
  33. return this.conn;
  34. }
  35.  
  36. public PreparedStatement getStatement(String qry) {
  37. try {
  38. return getConnection().prepareStatement(qry);
  39. } catch (SQLException e) {
  40. e.printStackTrace();
  41. return null;
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement