DB Class Reference
List of all members.
|
Public Member Functions |
| void | connect () |
| void | execute (String sql) throws SQLException |
| ResultSet | getResult (String sql) throws SQLException |
| void | execute (String sql, String[] params) throws SQLException |
Static Public Member Functions |
| static DB | getInstance () |
Static Public Attributes |
| static Connection | conn = null |
Member Function Documentation
| void DB::connect |
( |
|
) |
[inline] |
00034 {
00035
00036 try {
00037
00038
00039 Class.forName("com.mysql.jdbc.Driver").newInstance();
00040 } catch (Exception ex) {
00041 System.out.println("JDBC Not loaded! " + ex);
00042 System.exit(-1);
00043 }
00044
00045 try {
00046 conn = DriverManager.getConnection("jdbc:mysql://localhost/proxy?" +
00047 "user=work&password=w0rk1nG");
00048 } catch (SQLException ex) {
00049
00050 System.out.println("SQLException: " + ex.getMessage());
00051 System.out.println("SQLState: " + ex.getSQLState());
00052 System.out.println("VendorError: " + ex.getErrorCode());
00053 System.exit(-1);
00054 }
00055 }
| void DB::execute |
( |
String |
sql, |
|
|
String[] |
params | |
|
) |
| | throws SQLException [inline] |
00107 {
00108 if (!checkConnection()){
00109 connect();
00110 }
00111 try{
00112 PreparedStatement prepStmt = conn.prepareStatement(sql);
00113 for (int i = 0; i < params.length; i++){
00114 prepStmt.setString(i+1, params[i]);
00115 }
00116 prepStmt.executeUpdate();
00117 prepStmt.close();
00118 }catch (SQLException e){
00119 System.out.println("Execute failed with " + e);
00120 }
00121 }
| void DB::execute |
( |
String |
sql |
) |
throws SQLException [inline] |
00057 {
00058 if (!checkConnection()){
00059 connect();
00060 }
00061 Statement stmt = null;
00062
00063 try {
00064 stmt = conn.createStatement();
00065 if (stmt.execute(sql)) {
00066 stmt = null;
00067 }
00068 } catch (SQLException e) {
00069 stmt = null;
00070 System.out.println(e);
00071 }
00072 }
| static DB DB::getInstance |
( |
|
) |
[inline, static] |
00016 {
00017 if (_theInstance == null) {
00018 throw new RuntimeException("No singleton instance available");
00019 } else {
00020 return _theInstance;
00021 }
00022 }
| ResultSet DB::getResult |
( |
String |
sql |
) |
throws SQLException [inline] |
00074 {
00075 if (!checkConnection()){
00076 connect();
00077 }
00078 Statement stmt = null;
00079
00080 try {
00081 stmt = conn.createStatement();
00082 if (stmt.execute(sql)) {
00083 ResultSet rs = stmt.getResultSet();
00084 stmt = null;
00085 return rs;
00086 }
00087 } catch (SQLException e) {
00088 stmt = null;
00089 System.out.println("Can't get resultSet " + e);
00090 }
00091 return null;
00092 }
Member Data Documentation
The documentation for this class was generated from the following file: