Guest User

Untitled

a guest
Feb 4th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. package com.dev.code.adda.config;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.util.Properties;
  6.  
  7. import com.google.common.base.Throwables;
  8.  
  9. public class DBConfig {
  10.  
  11. private static String jdbcUrl;
  12. private static String username;
  13. private static String password;
  14. private static String driverClassName;
  15.  
  16. public static String getJdbcUrl() {
  17. return jdbcUrl;
  18. }
  19. public static void setJdbcUrl(String jdbcUrl) {
  20. DBConfig.jdbcUrl = jdbcUrl;
  21. }
  22. public static String getUsername() {
  23. return username;
  24. }
  25. public static void setUsername(String username) {
  26. DBConfig.username = username;
  27. }
  28. public static String getPassword() {
  29. return password;
  30. }
  31. public static void setPassword(String password) {
  32. DBConfig.password = password;
  33. }
  34. public static String getDriverClassName() {
  35. return driverClassName;
  36. }
  37. public static void setDriverClassName(String driverClassName) {
  38. DBConfig.driverClassName = driverClassName;
  39. }
  40.  
  41. static {
  42. File file = null;
  43. FileInputStream fileInputStream = null;
  44. Properties properties=null;
  45. try {
  46. file = new File(System.getProperty("user.dir") + File.separator + "mysql-file-insert-config"
  47. + File.separator + "DBConnection.properties");
  48. fileInputStream = new FileInputStream(file);
  49. properties = new Properties();
  50. properties.load(fileInputStream);
  51.  
  52. setDriverClassName(properties.getProperty("driverClassName"));
  53. setJdbcUrl(properties.getProperty("jdbcUrl"));
  54. setUsername(properties.getProperty("username"));
  55. setPassword(properties.getProperty("password"));
  56.  
  57. } catch (Exception ex) {
  58. System.out.println("Exception occured while reading properties file:" + Throwables.getStackTraceAsString(ex));
  59. } finally {
  60. if (fileInputStream != null) {
  61. try {
  62. fileInputStream.close();
  63. } catch (Exception se) {
  64. System.out.println("Error closing the FileInputStream object" + Throwables.getStackTraceAsString(se));
  65. }
  66. }
  67. }
  68.  
  69. }
  70. }
Add Comment
Please, Sign In to add comment