Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. public class SQL {
  2.  
  3. public static Connection connection;
  4. public static String SQLiteCreateTokensTable = "CREATE TABLE IF NOT EXISTS SkyBlock_Day(UUID VARCHAR(100), Day INT, Time LONG, TimeAfter LONG);";
  5. public static String table = "SkyBlock_Day";
  6.  
  7. public static Connection getSQLConnection() {
  8. File dataFolder = new File("SkyBlock.db");
  9.  
  10. if (!dataFolder.exists()){
  11. try {
  12. dataFolder.createNewFile();
  13. } catch (IOException e) {}
  14. }
  15. try {
  16. if(connection != null && !connection.isClosed()){
  17. return connection;
  18. }
  19. Class.forName("org.sqlite.JDBC");
  20. connection = DriverManager.getConnection("jdbc:sqlite:SkyBlock.db");
  21. return connection;
  22. } catch (SQLException ex) {} catch (ClassNotFoundException ex) {}
  23. return null;
  24.  
  25. }
  26.  
  27. public static boolean isConnected(){
  28. return (connection == null ? false : true);
  29. }
  30.  
  31. public static void disconnect(){
  32. if(isConnected()){
  33. try{
  34. connection.close();
  35. }catch(SQLException e){
  36.  
  37. }
  38. }
  39. }
  40.  
  41.  
  42.  
  43. public static void load() {
  44. connection = getSQLConnection();
  45. try {
  46. Statement s = connection.createStatement();
  47. s.executeUpdate(SQLiteCreateTokensTable);
  48. s.close();
  49. } catch (SQLException e) {}
  50. }
  51.  
  52. public static void update(String qry) {
  53. try {
  54. Statement st = connection.createStatement();
  55. st.executeUpdate(qry);
  56. st.close();
  57. } catch (SQLException e) {
  58. getSQLConnection();
  59. }
  60. }
  61.  
  62. public static ResultSet query(String qry) {
  63. ResultSet rs = null;
  64.  
  65. try {
  66. Statement st = connection.createStatement();
  67. rs = st.executeQuery(qry);
  68. } catch (SQLException e) {
  69. getSQLConnection();
  70. }
  71. return rs;
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement