Yurttas/PL/DBL/mssql/F/04/02/00/DatabaseManager.java
Jump to navigation
Jump to search
1/**
2 * Copyright(C) 2003
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : June 1, 2003.
11 * @author : Salih Yurttas, Brian Autry.
12 */
13
14
15import java.sql.*;
16
17public class DatabaseManager {
18
19 private Connection con;
20 private Statement state;
21 private ResultSet rSet;
22
23 public DatabaseManager() {}
24
25 public String update(String q) {
26 String results = "Update Failed!";
27 try {
28 Class.forName("com.mysql.jdbc.Driver").newInstance();
29 con = DriverManager.getConnection("jdbc:mysql://localhost/bank",
30 "tester",
31 "tester");
32 state = con.createStatement();
33 state.executeUpdate(q);
34 results = "Successful Update!";
35 }
36 catch(Exception e) {
37 e.printStackTrace();
38 }
39
40 return results;
41 }
42
43 public ResultSet query(String q) {
44 try {
45 Class.forName("com.mysql.jdbc.Driver").newInstance();
46 con = DriverManager.getConnection("jdbc:mysql://localhost/banky",
47 "tester",
48 "tester");
49
50 state = con.createStatement();
51 rSet = state.executeQuery(q);
52 }
53 catch(Exception e) {
54 e.printStackTrace();
55 rSet = null;
56 }
57 return rSet;
58 }
59
60}