Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package utils;
- import java.sql.Connection;
- import java.sql.SQLException;
- import javax.naming.InitialContext;
- import javax.naming.NamingException;
- import javax.sql.DataSource;
- /**
- * Created by User on 24.11.2017.
- */
- public class ConectionManager {
- public Connection getConnection() {
- InitialContext initContext = null;
- try {
- initContext = new InitialContext();
- } catch (NamingException e) {
- e.printStackTrace();
- }
- DataSource ds = null;
- try {
- ds = (DataSource) initContext.lookup("java:comp/env/jdbc/ps13_db");
- } catch (NamingException e1) {
- e1.printStackTrace();
- }
- Connection con = null;
- try {
- con = ds.getConnection();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement