Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.davidev.punir.utils;
- import java.io.File;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- public class SQL
- {
- private Connection conn;
- private File file;
- private Statement stmt;
- private SQL(File f)
- {
- this.file = f;
- try
- {
- Class.forName("org.sqlite.JDBC");
- this.conn = DriverManager.getConnection("jdbc:sqlite:" + this.file);
- this.stmt = this.conn.createStatement();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- private SQL(String urlconn)
- {
- try
- {
- this.conn = DriverManager.getConnection(urlconn);
- this.stmt = this.conn.createStatement();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public static SQL load(File f)
- {
- return new SQL(f);
- }
- public static SQL load(String f)
- {
- return new SQL(new File(f));
- }
- public static SQL load(String host, String database, String user, String pass)
- {
- return new SQL("jdbc:mysql://" + host + "/" + database + "?user=" + user + "&password=" + pass);
- }
- public void update(String q)
- {
- try
- {
- this.stmt.executeUpdate(q);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public ResultSet query(String q)
- {
- try
- {
- return this.stmt.executeQuery(q);
- }
- catch (Exception localException) {}
- return null;
- }
- public void close()
- {
- try
- {
- this.stmt.close();
- this.conn.close();
- }
- catch (Exception localException) {}
- }
- public boolean isConnected()
- {
- try
- {
- return (this.stmt != null) && (this.conn != null) && (!this.stmt.isClosed()) && (!this.conn.isClosed());
- }
- catch (Exception localException) {}
- return false;
- }
- public Connection getConnection()
- {
- return this.conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement