Guest User

Untitled

a guest
Nov 16th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. package managers;
  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. public final class DatabaseConnection {
  11. private static DataSource dataSource;
  12.  
  13. static {
  14. try {
  15. dataSource = (DataSource) new InitialContext().lookup("jdbc/MySQLDataSource");
  16. System.out.println("Connection is established!");
  17. } catch (NamingException e) {
  18. throw new ExceptionInInitializerError(e);
  19. }
  20. }
  21.  
  22. public static Connection getConnection() throws SQLException {
  23. return dataSource.getConnection();
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment