Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. package com.rs2hd.util.database;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.Driver;
  5. import java.sql.DriverManager;
  6. import java.sql.DriverPropertyInfo;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.util.Properties;
  11.  
  12. public class MySQLAdaptor implements Driver {
  13.  
  14.  
  15. public static final String HOST = "";
  16. public static final String DATABASE = "";
  17. public static final String USERNAME = "";
  18. public static final String PASSWORD = "";
  19. public static final String URL = "jdbc:mysql://" + HOST + "/" + DATABASE;
  20. private Connection c = null;
  21.  
  22. public MySQLAdaptor() {
  23. try {
  24. DriverManager.registerDriver(this);
  25. } catch (SQLException e) {
  26. e.printStackTrace();
  27. }
  28. try {
  29. Class.forName("com.mysql.jdbc.Driver").newInstance();
  30. c = DriverManager.getConnection(MySQLAdaptor.URL, MySQLAdaptor.USERNAME, MySQLAdaptor.PASSWORD);
  31. } catch (InstantiationException e) {
  32. e.printStackTrace();
  33. } catch (IllegalAccessException e) {
  34. e.printStackTrace();
  35. } catch (ClassNotFoundException e) {
  36. e.printStackTrace();
  37. } catch (SQLException e) {
  38. e.printStackTrace();
  39. }
  40.  
  41. }
  42.  
  43. public Connection getConnection() {
  44. return c;
  45. }
  46.  
  47. public ResultSet executeQuery(String query) throws SQLException {
  48. Statement stmt = getConnection().createStatement();
  49. ResultSet rs = stmt.executeQuery(query);
  50. return rs;
  51. }
  52.  
  53. public void executeUpdate(String query) throws SQLException {
  54. Statement stmt = getConnection().createStatement();
  55. stmt.executeUpdate(query);
  56. }
  57.  
  58. public static MySQLAdaptor singleton;
  59. public static MySQLAdaptor getSingleton() {
  60. return singleton == null ? (singleton = new MySQLAdaptor()) : singleton;
  61. }
  62.  
  63. public boolean acceptsURL(String arg0) throws SQLException {
  64. return arg0.startsWith("jdbc:jdc:");
  65. }
  66.  
  67. public Connection connect(String arg0, Properties arg1) throws SQLException {
  68. if(acceptsURL(arg0)) {
  69. return c;
  70. }
  71. return null;
  72. }
  73.  
  74. public int getMajorVersion() {
  75. return 1;
  76. }
  77.  
  78. public int getMinorVersion() {
  79. return 0;
  80. }
  81.  
  82. public DriverPropertyInfo[] getPropertyInfo(String arg0, Properties arg1)
  83. throws SQLException {
  84. return new DriverPropertyInfo[0];
  85. }
  86.  
  87. public boolean jdbcCompliant() {
  88. return false;
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement