import java.sql.*; import java.util.*; public class EURun { Connection con; ResourceBundle rb; Statement stmt; String sDriver, sDriverKey = "CSDriver", sKey, sPassword, sPasswordKey ="CSPassword", sUpdate, srbName = "ConnectU", srbUpdate, sURL, sURLKey="CSURL", sUserID, sUserIDKey = "CSUserID"; public EURun() 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 { try // get Connection and Statement { con = DriverManager.getConnection ( sURL, sUserID, sPassword); stmt = con.createStatement(); } catch ( SQLException SQLe) { reportSQLError( SQLe, "problems connecting to " + sURL + ":" ); 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()); }; int iProcessed = 0; // use <= since keys start with 1 for( int i = 1; i <= iCount; i++ ) { sKey = "" + i; sUpdate = rb.getString( sKey ); iProcessed += stmt.executeUpdate( sUpdate ); } System.out.println( iProcessed + " rows processed." ); } // 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) { // Report the problem SQL and error System.err.println( con.nativeSQL( sUpdate ) ); reportSQLError( SQLe, "problems with executeUpdate:" ); // rethrow the exception throw SQLe; } finally { try { stmt.close(); } catch( Exception e ) {} try { con.close(); } catch( Exception e ) {} } // end finally clause } // end doUpdate public void reportSQLError( SQLException SQLe, String s ) { System.err.println( s ); System.err.println( SQLe.getMessage() ); System.err.println( "SQL State: " + SQLe.getSQLState() ); } // end reportSQLError public static void main (String args[]) { boolean bContinue = true; EURun eurApp = null; if( args.length != 1 ) { System.err.println("Usage: " + "java EURun SQLUpdateResourceBundleName" ); return; } try { eurApp = new EURun(); } 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 EURun