Guest User

Untitled

a guest
Mar 9th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. package com.varun.util;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8. import java.util.Properties;
  9.  
  10. import com.arjuna.ats.internal.arjuna.recovery.Connection;
  11.  
  12. public class DbUtil {
  13.  
  14. private static Connection connection = null;
  15. public static Connection getConnection(){
  16. if(connection!=null)
  17. {
  18. return connection;
  19. }
  20. else
  21. {
  22. try{
  23.  
  24. Properties prop=new Properties();
  25. InputStream inputStream=DbUtil.class.getClassLoader().getResourceAsStream("/db.properties");
  26. prop.load(inputStream);
  27. String driver = prop.getProperty("driver");
  28. String url = prop.getProperty("url");
  29. String user = prop.getProperty("user");
  30. String password = prop.getProperty("password");
  31. Class.forName(driver);
  32. connection = (Connection) DriverManager.getConnection(url, user, password);
  33.  
  34. }catch(ClassNotFoundException e)
  35. {
  36. e.printStackTrace();
  37. }
  38. catch (SQLException e) {
  39. e.printStackTrace();
  40. } catch (FileNotFoundException e) {
  41. e.printStackTrace();
  42. } catch (IOException e) {
  43. e.printStackTrace();
  44. }
  45. return connection;
  46. }
  47. }
  48.  
  49. }
  50.  
  51. import com.arjuna.ats.internal.arjuna.recovery.Connection;
  52.  
  53. import java.sql.Connection;
  54.  
  55. import com.arjuna.ats.internal.arjuna.recovery.Connection;
  56.  
  57. import java.sql.Connection;
Add Comment
Please, Sign In to add comment