Advertisement
theTrixxter

Database class

Jan 29th, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. package com.theTrixxter.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. import org.bukkit.plugin.Plugin;
  9.  
  10. public abstract class database {
  11.  
  12. public Connection con;
  13. public Plugin plugin;
  14. public database(Plugin plugin){
  15. this.plugin = plugin;
  16. this.con = null;
  17. }
  18.  
  19. public abstract Connection openConnection() throws SQLException,
  20. ClassNotFoundException;
  21.  
  22. public boolean checkConnection() throws SQLException{
  23. return con != null && !con.isClosed();
  24. }
  25.  
  26. public Connection getConnection(){
  27. return con;
  28. }
  29.  
  30. public boolean closeConnection() throws SQLException{
  31. if(con == null){
  32. return false;
  33. }
  34. con.close();
  35. return true;
  36. }
  37.  
  38. public ResultSet querySQL(String s) throws SQLException,
  39. ClassNotFoundException{
  40. if(!checkConnection()){
  41. openConnection();
  42. }
  43. Statement st = con.createStatement();
  44. ResultSet rs = st.executeQuery(s);
  45. return rs;
  46. }
  47.  
  48. public int updateSQL(String s) throws SQLException,
  49. ClassNotFoundException{
  50. if(!checkConnection()){
  51. openConnection();
  52. }
  53. Statement st = con.createStatement();
  54. int rs = st.executeUpdate(s);
  55. return rs;
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement