Advertisement
eventhelawn

Untitled

Nov 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. package utils;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.SQLException;
  5.  
  6. import javax.naming.InitialContext;
  7. import javax.naming.NamingException;
  8. import javax.sql.DataSource;
  9. /**
  10. * Created by User on 24.11.2017.
  11. */
  12. public class ConectionManager {
  13.  
  14.  
  15. public Connection getConnection() {
  16.  
  17. InitialContext initContext = null;
  18. try {
  19. initContext = new InitialContext();
  20. } catch (NamingException e) {
  21. e.printStackTrace();
  22. }
  23. DataSource ds = null;
  24. try {
  25. ds = (DataSource) initContext.lookup("java:comp/env/jdbc/ps13_db");
  26. } catch (NamingException e1) {
  27. e1.printStackTrace();
  28. }
  29. Connection con = null;
  30. try {
  31. con = ds.getConnection();
  32. } catch (SQLException e) {
  33. e.printStackTrace();
  34. }
  35. return con;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement