Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rs2hd.util.database;
- import java.sql.Connection;
- import java.sql.Driver;
- import java.sql.DriverManager;
- import java.sql.DriverPropertyInfo;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Properties;
- public class MySQLAdaptor implements Driver {
- public static final String HOST = "";
- public static final String DATABASE = "";
- public static final String USERNAME = "";
- public static final String PASSWORD = "";
- public static final String URL = "jdbc:mysql://" + HOST + "/" + DATABASE;
- private Connection c = null;
- public MySQLAdaptor() {
- try {
- DriverManager.registerDriver(this);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- c = DriverManager.getConnection(MySQLAdaptor.URL, MySQLAdaptor.USERNAME, MySQLAdaptor.PASSWORD);
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public Connection getConnection() {
- return c;
- }
- public ResultSet executeQuery(String query) throws SQLException {
- Statement stmt = getConnection().createStatement();
- ResultSet rs = stmt.executeQuery(query);
- return rs;
- }
- public void executeUpdate(String query) throws SQLException {
- Statement stmt = getConnection().createStatement();
- stmt.executeUpdate(query);
- }
- public static MySQLAdaptor singleton;
- public static MySQLAdaptor getSingleton() {
- return singleton == null ? (singleton = new MySQLAdaptor()) : singleton;
- }
- public boolean acceptsURL(String arg0) throws SQLException {
- return arg0.startsWith("jdbc:jdc:");
- }
- public Connection connect(String arg0, Properties arg1) throws SQLException {
- if(acceptsURL(arg0)) {
- return c;
- }
- return null;
- }
- public int getMajorVersion() {
- return 1;
- }
- public int getMinorVersion() {
- return 0;
- }
- public DriverPropertyInfo[] getPropertyInfo(String arg0, Properties arg1)
- throws SQLException {
- return new DriverPropertyInfo[0];
- }
- public boolean jdbcCompliant() {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement