Advertisement
evgheni

Connection class

Jan 27th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.sql.Connection;
  2.  
  3. import javax.naming.Context;
  4. import javax.naming.InitialContext;
  5. import javax.sql.DataSource;
  6.  
  7.  
  8. public class ConnectionFactory {
  9.  
  10.    public static Connection getConnection(String dataSourceName) throws Exception{
  11.       try {
  12.          InitialContext ctx = new InitialContext();
  13.          Context envContext  = (Context)ctx.lookup("java:/comp/env");
  14.          DataSource ds = (DataSource)envContext.lookup(“jdbc/ProcBoffice_dbtestDS");
  15.         Connection conn = ds.getConnection();
  16.         conn.setAutoCommit(false);
  17.         return conn;
  18.      } catch (Exception e) {
  19.         throw new Exception("Errore in creazione Connessione : " + e.getMessage());
  20.      }
  21.   }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement