Guest User

Untitled

a guest
Dec 27th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public class Singleton {
  2.  
  3. private static Singleton INSTANCE = null;
  4.  
  5. private Connection connection;
  6.  
  7. public Singleton()
  8. {
  9.  
  10. }
  11.  
  12. public static Singleton getInstance()
  13. {
  14. if(INSTANCE == null)
  15. {
  16. INSTANCE = new Singleton();
  17. }
  18.  
  19. return INSTANCE;
  20. }
  21.  
  22. public void setSingletonConnexion(String URL, String userName, String password, String networkAlias) throws SQLException, ClassNotFoundException
  23. {
  24. Class.forName("oracle.jdbc.driver.OracleDriver");
  25.  
  26. System.setProperty("pathOfTNS");
  27.  
  28. //System.out.println("driver ok");
  29.  
  30. this.connection = DriverManager.getConnection("jdbc:oracle:thin:@"+URL+":PORT:SID", userName,password);
  31.  
  32. System.out.println("CO OK");
  33.  
  34. ResultSet rs = this.connection.createStatement().executeQuery("SELECT * FROM TABLE");
  35.  
  36. if(rs.next())
  37. {
  38. System.out.println(rs.getString(5));
  39. }
  40. }
  41.  
  42. public Connection getConnection()
  43. {
  44. return this.connection;
  45. }
Add Comment
Please, Sign In to add comment