Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DBQuery
- {
- private java.sql.Connection conn;
- DBQuery()
- {
- java.util.Properties info = new java.util.Properties();
- try( java.io.InputStream in = this.getClass().getResourceAsStream("myDB.properties") )
- {
- if( in != null )
- {
- info.load(in);
- this.conn = java.sql.DriverManager.getConnection(info.getProperty("url"), info.getProperty("user"), info.getProperty("password"));
- System.out.println("Connected to " + info.getProperty("url")+ " as User '"+info.getProperty("user")+"'!");
- }
- }
- catch( java.io.IOException | java.sql.SQLException e1)
- {
- System.err.println("Could not properly connect to Database!");
- System.err.println(e1);
- //safety!
- try
- {
- if( this.conn != null ) this.conn.close();
- }
- catch( java.sql.SQLException e2 )
- {
- System.err.println("Closing connection failed!");
- System.err.println(e2);
- }
- finally { System.exit(1); }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement