01: package forum;
02:
03: import javax.servlet.*;
04: import javax.servlet.http.*;
05: import java.sql.*;
06: import java.sql.Connection;
07: import java.sql.Statement;
08: import java.sql.ResultSet;
09: import org.gjt.mm.mysql.*;
10:
11: public class DBConnectie {
12:
13: String DBName, DBUser, DBPass, SQLQuery;
14: Connection conn;
15: Statement stmt;
16: ResultSet result;
17:
18: public DBConnectie(String DBName, String DBUser, String DBPass) {
19: this .DBName = DBName;
20: this .DBUser = DBUser;
21: this .DBPass = DBPass;
22: try {
23: Class.forName("org.gjt.mm.mysql.Driver");
24: } catch (Exception e) {
25: }
26: }
27:
28: public void connect() {
29: try {
30: conn = DriverManager
31: .getConnection("jdbc:mysql://localhost/" + DBName
32: + "?user=" + DBUser + "&password=" + DBPass);
33: } catch (Exception e) {
34: }
35: }
36:
37: public ResultSet selectQuery(String SQLQuery) {
38: this .SQLQuery = SQLQuery;
39:
40: try {
41: stmt = conn.createStatement();
42: result = stmt.executeQuery(SQLQuery);
43: } catch (Exception e) {
44: }
45: return result;
46: }
47:
48: public void query(String SQLQuery) {
49: this .SQLQuery = SQLQuery;
50: try {
51: stmt = conn.createStatement();
52: stmt.executeQuery(SQLQuery);
53: } catch (Exception e) {
54: }
55: }
56:
57: public void close() {
58: try {
59: stmt.close();
60: conn.close();
61: } catch (Exception e) {
62: }
63: }
64: }
|