Guest User

Untitled

a guest
Apr 15th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. public static void main(String[] args) throws SQLException {
  2.  
  3.     /* Get DB parameters from properties file */
  4.     String dbUser = rb.getString("username");
  5.     String dbPassword = rb.getString("password");
  6.     String dbUrl = rb.getString("url");
  7.     String driverClassName = rb.getString("driverClassName");
  8.  
  9.     /* Initialize the class with the given string name */
  10.     Class.forName(driverClassName);
  11.     logger.debug("Connecting to DB...");
  12.     Main.dbConnection = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
  13.  
  14.     if (null == Main.dbConnection) {
  15.         logger.fatal("Unable to connect to DB");
  16.     } else {
  17.         logger.info("Connected to DB");
  18.         Main.dbConnection.setAutoCommit(false);
  19.     }
  20.  
  21.     try {
  22.         /* Elaborate */
  23.         storeprocedure();
  24.  
  25.         dbConnection.commit();
  26.  
  27.         try {
  28.             dbConnection.close();
  29.         } catch (SQLException e) {
  30.             logger.fatal("Unable to close db connection" + e.getMessage());
  31.         }
  32.     } catch (Exception e) {
  33.         dbConnection.rollback();
  34.         e.printStackTrace();
  35.     }
  36. }
Add Comment
Please, Sign In to add comment