joseleonweb

Untitled

May 12th, 2021
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. Connection conn = null;
  2.  
  3. try(FileInputStream f = new FileInputStream("db.properties")) {
  4.     // load the properties file
  5.     Properties pros = new Properties();
  6.     pros.load(f);
  7.  
  8.     // assign db parameters
  9.     String url       = pros.getProperty("url");
  10.     String user      = pros.getProperty("user");
  11.     String password  = pros.getProperty("password");
  12.     // create a connection to the database
  13.     conn = DriverManager.getConnection(url, user, password);
  14. } catch(IOException e) {
  15.    System.out.println(e.getMessage());
  16. } finally {
  17.     try{
  18.         if(conn != null)
  19.             conn.close();
  20.     }catch(SQLException ex){
  21.         System.out.println(ex.getMessage());
  22.     }
  23.    
  24. }
Advertisement
Add Comment
Please, Sign In to add comment