Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xenon.sql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- /**
- * Deals with SQL stuffz.
- *
- * @author Colby
- */
- public class SQLEngine {
- private SQLEngine() {
- if(true)return;
- try {
- Class.forName("org.gjt.mm.mysql.Driver");
- genericConnection = getDedicatedConnection();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- /**
- * Used to generate a dedicated connection.
- */
- public Connection getDedicatedConnection() throws SQLException {
- return DriverManager.getConnection(SQL_URL, SQL_USERNAME, SQL_PASSWORD);
- }
- /**
- * Used to submit a query using a generic connection. This is synchronized
- * internally.
- */
- public ResultSet query(String query) throws SQLException {
- final Object lock = genericConnection;
- synchronized (lock) {
- return genericConnection.createStatement().executeQuery(query);
- }
- }
- /**
- * Executes an SQL command
- *
- * @param command
- * The command to execute
- * @throws SQLException
- * If an error occours executing the command
- */
- public void exec(String command) throws SQLException {
- Statement s = null;
- try {
- s = genericConnection.createStatement();
- s.executeUpdate(command);
- } finally {
- if (s != null) {
- s.close();
- }
- }
- }
- /**
- * Gets a singleton instance of SQLEngine
- */
- public static SQLEngine getSingleton() {
- return SINGLETON;
- }
- /**
- * The name of the SQL database
- */
- public static final String SQL_NAME = "sevdim_forum";
- /**
- * The password for the SQL database
- */
- public static final String SQL_PASSWORD = "yjgpn311";
- /**
- * The username for the SQL database
- */
- public static final String SQL_USERNAME = "sevdim_admin";
- /**
- * The port for the SQL database
- */
- public static final short SQL_PORT = 3306;
- /**
- * The IP for the SQL database
- */
- public static final String SQL_IP = "174.120.136.252";
- /**
- * The full URL of the databse
- */
- public static final String SQL_URL = "jdbc:mysql://" + SQL_IP + "/" + SQL_NAME;
- /**
- * A generic connection to use when you don't need a dedicated one.
- */
- private Connection genericConnection;
- /**
- * The SQLEngine singleton
- */
- private static final SQLEngine SINGLETON = new SQLEngine();
- }
Add Comment
Please, Sign In to add comment