Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.Properties;
- public class MySQLJDBCUtil {
- public static Connection getConnection() throws SQLException {
- 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());
- }
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment