Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package plugin.zozidalom.pp;
- import gyurix.spigotlib.SU;
- import org.sqlite.JDBC;
- import javax.swing.*;
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class MySQL {
- static Connection con = null;
- static boolean b;
- static PreparedStatement state;
- public static void setCon() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/zozidalom", "root", "Gumicukor462");
- System.out.println(con.toString());
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- public static Connection getCon() throws Exception {
- if (con == null) {
- setCon();
- }
- return con;
- }
- public static boolean putData(String sql) {
- try {
- getCon().setAutoCommit(false);
- state = getCon().prepareStatement(sql);
- state.executeUpdate();
- getCon().commit();
- b = true;
- } catch (Exception e) {
- e.printStackTrace();
- b = false;
- }
- return b;
- }
- // connection commit
- public static void commit() {
- try {
- con.commit();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- // rollback data
- public static void rollback() {
- if (con != null) {
- try {
- con.rollback();
- } catch (SQLException ex) {
- Logger.getLogger(JDBC.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- // close statement
- public static void putClose() {
- try {
- state.close();
- } catch (SQLException ex) {
- Logger.getLogger(JDBC.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- // close connection
- public static void conClose() {
- try {
- con.setAutoCommit(true);
- con.close();
- } catch (SQLException ex) {
- Logger.getLogger(JDBC.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- // clear prepared statement
- public static void putClear() {
- try {
- if (state != null && !state.isClosed()) {
- state.close();
- }
- } catch (SQLException ex) {
- Logger.getLogger(JDBC.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- // clear the connection
- public static void conClear() {
- try {
- if (con != null && !con.isClosed()) {
- con.setAutoCommit(true);
- con.close();
- }
- } catch (SQLException ex) {
- Logger.getLogger(JDBC.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static ResultSet getData(String sql) throws Exception {
- Statement state = getCon().createStatement();
- ResultSet rs = state.executeQuery(sql);
- return rs;
- }
- public static int update(String cmd)
- {
- try
- {
- PreparedStatement st = getCon().prepareStatement(cmd);
- return st.executeUpdate();
- }
- catch (Throwable e)
- {
- SU.error(SU.cs, e, "SpigotLib", "gyurix");
- }
- return -1;
- }
- }
Add Comment
Please, Sign In to add comment