Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package com.RS09HD.MySQL;
  2.  
  3.  
  4. import com.RS09HD.model.ObjectDefinition;
  5.  
  6. import java.sql.*;
  7.  
  8. public final class SqlManager {
  9. // JDBC driver name and database URL
  10. static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  11. static final String DB_URL = "jdbc:mysql://localhost/rs09hd";
  12.  
  13. // Database credentials
  14. static final String USER = "server";
  15. static final String PASS = "Runescape09";
  16.  
  17. private static boolean initialized;
  18.  
  19. public SqlManager() {
  20.  
  21. }
  22.  
  23. public static void init() {
  24. Connection conn = null;
  25. Statement stmt = null;
  26. try {
  27. //Initialize sql manager
  28. Class.forName("com.mysql.jdbc.Driver");
  29. } catch (ClassNotFoundException e) {
  30. e.printStackTrace();
  31. initialized = false;
  32. return;
  33. }
  34. initialized = true;
  35. }
  36.  
  37. public static Connection getConnection() {
  38. try {
  39. return DriverManager.getConnection(DB_URL, USER, PASS);
  40. } catch (SQLException e) {
  41. System.out.println("Error: Mysql Error:" + e.getMessage());
  42. }
  43. return null;
  44. }
  45.  
  46.  
  47.  
  48. public static void close(Connection connection) {
  49. try {
  50. connection.close();
  51. } catch(SQLException e) {
  52. e.printStackTrace();
  53. }
  54. }
  55.  
  56. public static boolean isInitialized() { return initialized;}
  57.  
  58. public static void setInitialized(boolean initialized) {SqlManager.initialized = initialized;}
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement