Advertisement
Guest User

Untitled

a guest
May 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. package eu.pixeldream.api.sql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. import eu.pixeldream.api.API;
  9.  
  10. public class Mysql2 {
  11.       private API plugin;
  12.       private String HOST = null;
  13.       private String DB = null;
  14.       private String USER = null;
  15.       private String PASS = null;
  16.       private boolean connected = false;
  17.  
  18.       private Statement st = null;
  19.       private Connection con = null;
  20.       private MySQLFunc MySQL;
  21.      
  22.       public void MySQL()
  23.       {
  24.         this.plugin = API.getInstance();
  25.         plugin.getDescription().getName();
  26.         this.connected = false;
  27.       }
  28.  
  29.   public Boolean Connect() {
  30.     this.HOST = "localhost";
  31.     this.DB = "network_servers";
  32.     this.USER = "network_servers";
  33.     this.PASS = "YN39gq2i";
  34.     this.MySQL = new MySQLFunc(this.HOST, this.DB, this.USER, this.PASS);
  35.     this.con = this.MySQL.open();
  36.     try {
  37.       this.st = this.con.createStatement();
  38.       this.connected = true;
  39.     } catch (SQLException e) {
  40.       this.connected = false;
  41.       e.printStackTrace();
  42.     }
  43.     this.MySQL.close(this.con);
  44.     return Boolean.valueOf(this.connected);
  45.   }
  46.  
  47.   public int countRows(String table)
  48.   {
  49.     int count = 0;
  50.     ResultSet set = query(String.format("SELECT * FROM %s", new Object[] { table }));
  51.     try {
  52.       while (set.next())
  53.         count++;
  54.     }
  55.     catch (SQLException e) {
  56.         e.printStackTrace();
  57.     }
  58.     return count;
  59.   }
  60.  
  61.   public void update(String query) {
  62.     this.MySQL = new MySQLFunc(this.HOST, this.DB, this.USER, this.PASS);
  63.     this.con = this.MySQL.open();
  64.     try {
  65.       this.st = this.con.createStatement();
  66.       this.st.execute(query);
  67.     } catch (SQLException e) {
  68.         e.printStackTrace();
  69.     }
  70.     this.MySQL.close(this.con);
  71.   }
  72.  
  73.   public ResultSet query(String query) {
  74.     this.MySQL = new MySQLFunc(this.HOST, this.DB, this.USER, this.PASS);
  75.     this.con = this.MySQL.open();
  76.     ResultSet rs = null;
  77.     try {
  78.       this.st = this.con.createStatement();
  79.       rs = this.st.executeQuery(query);
  80.     } catch (SQLException e) {
  81.         e.printStackTrace();
  82.     }
  83.     this.MySQL.close(this.con);
  84.     return rs;
  85.   }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement