Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ?;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- public class AsyncMySQL {
- private Connection conn;
- private String database;
- private String host;
- private String passwort;
- private String port;
- private String user;
- public AsyncMySQL(String host, String port, String user, String passwort, String database) {
- this.host = host;
- this.port = port;
- this.user = user;
- this.passwort = passwort;
- this.database = database;
- }
- public Connection getConnection() {
- try {
- if (this.conn == null || this.conn.isClosed()) {
- this.conn = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.user, this.passwort);
- System.out.println("Also die Verbindung ist schon mal da.");
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return this.conn;
- }
- public PreparedStatement getStatement(String qry) {
- try {
- return getConnection().prepareStatement(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement