Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Database connection through config.properties
- import java.io.FileInputStream;
- import java.sql.*;
- import javax.swing.*;
- import java.io.IOException;
- import java.util.Properties;
- public class JavaConnect {
- Connection conn = null;
- static String url_database;
- static String username;
- static String password;
- public void OutProp (){
- Properties prop = new Properties();
- try {
- prop.load(new FileInputStream("config.properties"));
- url_database = prop.getProperty("Url");
- username = prop.getProperty("Username");
- password = prop.getProperty("Password");
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- public static Connection ConnectDb(){
- try{
- Class.forName ("com.mysql.jdbc.Driver");
- Connection conn = DriverManager.getConnection (url_database,username,password);
- return conn;
- }
- catch (Exception e) {
- JOptionPane.showMessageDialog(null, e);
- return null;
- }
- }
- }
- Property1=value1
- Property2=value2
Add Comment
Please, Sign In to add comment