1 29 38 39 package org.planetamessenger.db; 40 41 import java.sql.Connection ; 42 import java.sql.PreparedStatement ; 43 44 45 public class JDatabase { 46 47 boolean bDriverOK = true; 48 java.sql.Connection conn = null; 49 50 51 52 58 public JDatabase( java.lang.String strDriverName ) throws java.lang.Exception { 59 60 try { 62 Class.forName( strDriverName ); 63 } catch( java.lang.Exception e ) { 64 bDriverOK = false; 65 throw e; 66 } 67 } 68 69 73 public void destroy() { 74 75 close(); 76 conn = null; 77 } 78 79 87 public boolean open( java.lang.String strConnection, java.lang.String strUserName, java.lang.String strPassword ) { 88 89 try { 90 conn = java.sql.DriverManager.getConnection( strConnection, strUserName, strPassword ); 91 } catch( java.sql.SQLException e ) { 92 System.err.println( "JDatabase.open() - SQLException: " + e ); 93 return false; 94 } 95 96 return true; 97 } 98 99 103 public boolean close() { 104 105 if( bDriverOK ) { 106 try { 107 conn.close(); 108 } catch( java.sql.SQLException e ) { 109 System.err.println( "JDatabase.close() - SQLException: " + e ); 110 return false; 111 } 112 } 113 114 return true; 115 } 116 117 118 public Connection getConnection() { 119 return conn; 120 } 121 122 128 public JResultSet execSQL( java.lang.String strQuery ) { 129 130 if( bDriverOK ) { 131 try { 132 java.sql.Statement stmt = conn.createStatement(); 133 java.sql.ResultSet rs = stmt.executeQuery( strQuery ); 134 JResultSet resultSet = new JResultSet( stmt, rs ); 135 136 return resultSet; 137 } catch( java.sql.SQLException e ) { 138 System.err.println( "JDatabase.execSQL() - SQLException: " + e ); 139 } 140 } 141 142 return null; 143 } 144 145 151 public int execUpdate( java.lang.String strSQL ) { 152 153 if( bDriverOK ) { 154 try { 155 java.sql.Statement stmt = conn.createStatement(); 156 int nRowsAffcted = stmt.executeUpdate( strSQL ); 157 158 return nRowsAffcted; 159 } catch( java.sql.SQLException e ) { 160 System.err.println( "JDatabase.execUpdate() - SQLException: " + e ); 161 } 162 } 163 164 return -1; 165 } 166 167 172 public boolean execute( String strSQL ) { 173 174 if( bDriverOK ) { 175 try { 176 java.sql.Statement stmt = conn.createStatement(); 177 178 stmt.execute( strSQL ); 179 180 return true; 181 } catch( java.sql.SQLException e ) { 182 System.err.println( "JDatabase.execute() - SQLException: " + e ); 183 } 184 } 185 186 return false; 187 } 188 } 189 190 | Popular Tags |