Skip to content

Instantly share code, notes, and snippets.

@darbyluv2code
Created February 26, 2019 02:25
Show Gist options
  • Save darbyluv2code/41f67fb8c0fc3f6b04faad83c52eb196 to your computer and use it in GitHub Desktop.
Save darbyluv2code/41f67fb8c0fc3f6b04faad83c52eb196 to your computer and use it in GitHub Desktop.
TestJdbc (read configs from props file)
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