Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection conn = null;
- try(FileInputStream f = new FileInputStream("db.properties")) {
- // load the properties file
- Properties pros = new Properties();
- pros.load(f);
- // assign db parameters
- String url = pros.getProperty("url");
- String user = pros.getProperty("user");
- String password = pros.getProperty("password");
- // create a connection to the database
- conn = DriverManager.getConnection(url, user, password);
- } catch(IOException e) {
- System.out.println(e.getMessage());
- } finally {
- try{
- if(conn != null)
- conn.close();
- }catch(SQLException ex){
- System.out.println(ex.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment