import java.sql.*; import java.util.*; public class EURun2 { Connection con; ResourceBundle rb; SQLWarning sqlw; Statement stmt; String sDriver, sDriverKey = "CSDriver", sKey, sPassword, sPasswordKey ="CSPassword", sUpdate, srbName = "ConnectU", srbUpdate, sURL, sURLKey="CSURL", sUserID, sUserIDKey = "CSUserID"; public EURun2() throws MissingResourceException, ClassNotFoundException, InstantiationException, IllegalAccessException { // get the PropertyResourceBundle rb = ResourceBundle.getBundle( srbName ); sDriver = rb.getString( sDriverKey ); sPassword = rb.getString( sPasswordKey ); sURL = rb.getString( sURLKey ); sUserID = rb.getString( sUserIDKey ); // Attempt to load the JDBC driver // with newInstance Class.forName( sDriver ).newInstance(); } // end constructor public void doUpdate( String sargRBName ) throws MissingResourceException, SQLException { int iProcessed = 0, iProcessedCount =0; try // get Connection and Statement { con = DriverManager.getConnection ( sURL, sUserID, sPassword); stmt = con.createStatement(); // insert code to get/handle con warnings // end insert } // end try catch ( SQLException SQLe) { // insert code to invoke handleSQLExceptions() // end insert if( con != null) { try { con.close(); } catch( Exception e ) {} } // rethrow the exception throw SQLe; } // end catch try { Enumeration e = null; int iCount = 0; // get the PropertyResourceBundle // for SQL update statements rb = ResourceBundle.getBundle( sargRBName ); e = rb.getKeys(); // Count keys - keys start at 1. for( ; e.hasMoreElements(); iCount++ ) { (e.nextElement()); }; // use <= since keys start with 1 for( int i = 1; i <= iCount; i++ ) { sKey = "" + i; sUpdate = rb.getString( sKey ); iProcessed = stmt.executeUpdate( sUpdate ); // insert code to report zero processed else total // end insert // insert code to get/handle stmt warnings // end insert } // end for } // end try catch( MissingResourceException mre ) { System.err.println( "ResourceBundle problem for " + sargRBName + ", program ends." ); System.err.println("Specific error: " + mre.getMessage() ); throw mre; } catch ( SQLException SQLe) { // insert code to invoke handleSQLExceptions() // end insert // rethrow the exception throw SQLe; } finally { // insert code to report total rows processed // end insert try { stmt.close(); } catch( Exception e ) {} try { con.close(); } catch( Exception e ) {} } // end finally clause } // end doUpdate public void handleSQLExceptions( SQLException SQLe, String s, String sSQL ) { boolean bFirstPass = true; // insert code to invoke reportSQLExceptions() // for all exceptions // end insert } // end handleSQLExceptions public void handleSQLWarnings( SQLWarning SQLw, String s, String sSQL ) { boolean bFirstPass = true; if( s == null ) { s = "SQLWarning:"; } // insert code to invoke reportSQLExceptions() // for all warnings // end insert } // end handleSQLWarnings public void reportSQLExceptions( SQLException SQLe, String s, String sSQL ) { String sSQLState = null; // insert code for reporting // including DataTruncation // end insert } // end reportSQLExceptions public static void main (String args[]) { boolean bContinue = true; EURun2 eurApp = null; if( args.length != 1 ) { System.err.println("Usage: " + "java EURun2 SQLUpdateResourceBundleName" ); return; } try { eurApp = new EURun2(); } catch( Exception e ) { System.err.println("Constructor Exception: " + e.getMessage() ); bContinue = false; } if( bContinue ) { try { eurApp.doUpdate( args[0] ); } catch( Exception e ) {} } } // end main } // end class EURun2