Created
February 26, 2019 02:25
-
-
Save darbyluv2code/41f67fb8c0fc3f6b04faad83c52eb196 to your computer and use it in GitHub Desktop.
TestJdbc (read configs from props file)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.luv2code.jdbc; | |
| import java.io.FileInputStream; | |
| import java.io.IOException; | |
| import java.sql.Connection; | |
| import java.sql.DriverManager; | |
| import java.util.Properties; | |
| public class TestJdbc { | |
| public static void main(String[] args) throws Exception { | |
| // set up properties | |
| Properties myCustomProps = new Properties(); | |
| try { | |
| myCustomProps.load(new FileInputStream("c:\\test\\junk\\demo\\mickey-mouse.properties")); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| throw e; | |
| } | |
| String jdbcUrl = myCustomProps.getProperty("hibernate.connection.url"); | |
| String user = myCustomProps.getProperty("hibernate.connection.username"); | |
| String pass = myCustomProps.getProperty("hibernate.connection.password"); | |
| try { | |
| System.out.println("Connecting to database: " + jdbcUrl); | |
| Connection myConn = | |
| DriverManager.getConnection(jdbcUrl, user, pass); | |
| System.out.println("Connection successful!!!"); | |
| } | |
| catch (Exception exc) { | |
| exc.printStackTrace(); | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment