Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.cadedev.testplugin.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class MySQL {
- private String HOST = "";
- private String USER = "";
- private String PASSWORD = "";
- private String DATABASE = "";
- private Connection connection;
- public MySQL(String Host, String Datenbank, String Benutzername, String Passwort) {
- this.HOST = Host;
- this.USER = Benutzername;
- this.PASSWORD = Passwort;
- this.DATABASE = Datenbank;
- setConnect();
- }
- public void setConnect() {
- try {
- this.connection = DriverManager.getConnection("jdbc:mysql://" + this.HOST + ":3306/" + this.DATABASE + "?autoReconnect=true", this.USER,this.PASSWORD);
- System.out.println("[MySQL] Verbindung hergestellt");
- } catch (SQLException e) {
- System.out.println("[MySQL] Fehler: " + e.getMessage());
- }
- }
- public void setUpdate(String qry) {
- try {
- Statement st = this.connection.createStatement();
- st.executeUpdate(qry);
- st.close();
- } catch (SQLException e) {
- setConnect();
- System.err.println(e);
- }
- }
- public ResultSet setQuery(String qry) {
- ResultSet resultSet = null;
- try {
- Statement st = this.connection.createStatement();
- resultSet = st.executeQuery(qry);
- } catch (SQLException e) {
- setConnect();
- System.err.println(e);
- }
- return resultSet;
- }
- public void setClose() {
- try {
- if (this.connection != null) {
- this.connection.close();
- System.out.println("[MySQL] Verbindung aufgebaut zur MySQL");
- }
- } catch (SQLException e) {
- System.out.println("[MySQL] Fehler:" + e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement