Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private String HOST = "";
- private String DATABASE = "";
- private String USER = "";
- private String PASSWORD = "";
- private static Connection con;
- public MySQL(String host, String database, String user, String password)
- {
- this.HOST = host;
- this.DATABASE = database;
- this.USER = user;
- this.PASSWORD = password;
- connect();
- }
- public void connect() {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + this.HOST + ":3306/" + this.DATABASE + "?autoReconnect=true", this.USER, this.PASSWORD);
- System.out.println("MySQL » Erfolgreich hergestellt");
- } catch (SQLException e) {
- System.out.println("MySQL » Fehler | Fehler: " + e.getMessage());
- }
- }
- public void close() {
- try {
- if (con != null) {
- con.close();
- System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
- }
- } catch (SQLException e) {
- System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
- }
- }
- public void update(String qry) {
- try {
- Statement st = con.createStatement();
- st.executeUpdate(qry);
- st.close();
- } catch (SQLException e) {
- connect();
- System.err.println(e);
- }
- }
- public ResultSet query(String qry) {
- ResultSet rs = null;
- try
- {
- Statement st = con.createStatement();
- rs = st.executeQuery(qry);
- } catch (SQLException e) {
- connect();
- System.err.println(e);
- }
- return rs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement