Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySqL {
- private String HOST = "";
- private String DATABASE = "";
- private String USER = "";
- private String PASSWORD = "";
- private 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://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD);
- System.out.println("[PiratesPvP]MySQL foi preparado!");
- } catch (SQLException e) {
- System.out.println("[PiratesPvP] MySQL falhou ! erro: " + e.getMessage());
- }
- }
- public void close() {
- try {
- if(con != null) {
- con.close();
- System.out.println("A conexão com MySQL foi concluida com exito!");
- }
- } catch (SQLException e) {
- System.out.println("Falha ao interromper a ligação ao MySQL! erro: " + 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