View difference between Paste ID: BvcDRrxr and n319kBAx
SHOW: | | - or go back to the newest paste.
1-
package com.brinedev.libs.db;
1+
package me.trow.Classe;
2
3
import java.io.File;
4
import java.sql.Connection;
5
import java.sql.DriverManager;
6
import java.sql.ResultSet;
7
import java.sql.Statement;
8
 
9-
public class Database {
9+
public class DB {
10
	
11
	private Connection conn;
12
	private File file;
13
	private Statement stmt;
14
	
15-
	private Database(File f) {
15+
	private DB(File f) {
16
		file = f;
17
		try {
18
			Class.forName("org.sqlite.JDBC");
19
			conn = DriverManager.getConnection("jdbc:sqlite:" + file);
20
			stmt = conn.createStatement();
21
		} catch (Exception e) {
22
			e.printStackTrace();
23
		}
24
	}
25
 
26-
	private Database(String urlconn) {
26+
	private DB(String urlconn) {
27
		try {
28
			conn = DriverManager.getConnection(urlconn);
29
			stmt = conn.createStatement();
30
		} catch (Exception e) {
31
			e.printStackTrace();
32
		}
33
	}
34-
	public static Database load(File f) {
34+
 
35-
		return new Database(f);
35+
	public static DB load(File f) {
36
		return new DB(f);
37
	}
38-
	public static Database load(String f) {
38+
 
39-
		return new Database(new File(f));
39+
	public static DB load(String f) {
40
		return new DB(new File(f));
41
	}
42-
	public static Database load(String host, String database, String user,
42+
 
43
	public static DB load(String host, String database, String user,
44-
		return new Database("jdbc:mysql://" + host + "/" + database + "?"
44+
45
		return new DB("jdbc:mysql://" + host + "/" + database + "?"
46
				+ "user=" + user + "&password=" + pass);
47
	}
48
 
49
	public void update(String q) {
50
		try {
51
			stmt.executeUpdate(q);
52
		} catch (Exception e) {e.printStackTrace();}
53
	}
54
	
55
	public ResultSet query(String q) {
56
		try {
57
			return stmt.executeQuery(q);
58
		} catch (Exception e) {
59
		}
60
		return null;
61
	}
62
	
63
	public void close() {
64
		try {
65
			stmt.close();
66
			conn.close();
67
		} catch (Exception e) {}
68
	}
69
	
70
	public boolean isConnected() {
71
		try {
72-
		return stmt!=null && conn!=null && !stmt.isClosed() && !conn.isClosed();
72+
			return stmt!=null && conn!=null && !stmt.isClosed() && !conn.isClosed();
73
		} catch (Exception e) {}
74
		return false;
75
	}
76
77
	public Connection getConnection() {
78
		return conn;
79
	}
80
 
81
}