Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. public Connection getConnection(String name) throws SQLException {
  2. Connection connection=null;
  3. try {
  4. Context initContext = new InitialContext();
  5. DataSource ds = (DataSource) initContext.lookup(name);
  6. connection = ds.getConnection();
  7. } catch (SQLException e) {
  8. throw new SQLException("Connect "+name+ ", ErrorCode:" + e.getErrorCode() + ", Message:" + e.getMessage());
  9. } catch (NamingException e) {
  10. throw new SQLException("Connect "+name+ ", Message:" + e.getMessage());
  11. }
  12. return connection;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement