Guest User

Untitled

a guest
Jan 13th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. Database connection through config.properties
  2. import java.io.FileInputStream;
  3. import java.sql.*;
  4. import javax.swing.*;
  5. import java.io.IOException;
  6. import java.util.Properties;
  7.  
  8. public class JavaConnect {
  9.  
  10. Connection conn = null;
  11. static String url_database;
  12. static String username;
  13. static String password;
  14.  
  15. public void OutProp (){
  16.  
  17. Properties prop = new Properties();
  18.  
  19. try {
  20. prop.load(new FileInputStream("config.properties"));
  21.  
  22. url_database = prop.getProperty("Url");
  23. username = prop.getProperty("Username");
  24. password = prop.getProperty("Password");
  25.  
  26.  
  27. } catch (IOException ex) {
  28. ex.printStackTrace();
  29. }
  30. }
  31.  
  32.  
  33. public static Connection ConnectDb(){
  34.  
  35. try{
  36. Class.forName ("com.mysql.jdbc.Driver");
  37. Connection conn = DriverManager.getConnection (url_database,username,password);
  38.  
  39. return conn;
  40. }
  41. catch (Exception e) {
  42. JOptionPane.showMessageDialog(null, e);
  43. return null;
  44. }
  45. }
  46. }
  47.  
  48. Property1=value1
  49. Property2=value2
Add Comment
Please, Sign In to add comment