Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import de.crackexception.nick.api.Data;
- public class MySQL {
- public static Connection c;
- public static void connect(){
- try{
- c = DriverManager.getConnection("jdbc:mysql://" + Data.host + ":3306" + "/" + Data.db + "?autoReconnect=true",Data.user,Data.pw);
- System.out.println("[MySQL] Connected.");
- } catch(SQLException e){
- System.out.println("[MySQL] Connection failed.");
- e.printStackTrace();
- }
- }
- public static void disconnect() {
- if(c != null) {
- try {
- c.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void Update(String qry) {
- try {
- Statement stmt = c.createStatement();
- stmt.executeUpdate(qry);
- stmt.close();
- } catch (SQLException ex) {
- ex.printStackTrace();
- disconnect();
- connect();
- }
- }
- public static ResultSet query(String qry){
- ResultSet rs = null;
- try{
- Statement st = c.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