Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <GlobalNamingResources>
- <Resource
- auth="Container"
- driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
- logAbandoned="true"
- maxActive="20"
- maxIdle="10"
- maxWait="5000"
- name="jdbc/datasource1"
- removeAbandoned="true"
- removeAbandonedTimeout="60"
- type="javax.sql.DataSource"
- url="jdbc:sqlserver://localhost;databaseName=database1"
- username="username"
- password="password"/>
- </GlobalNamingResources>
- try {
- Context initCtx = new InitialContext();
- Context envCtx = (Context) initCtx.lookup("java:comp/env");
- DataSource ds = (DataSource) envCtx.lookup("datasource1");
- ds.getConnection(); // If this line doesn't throw SQLException, the db connection is established successfully
- } catch(NamingException ex) {
- System.out.println("JNDI lookup failed: " + ex.getMessage());
- } catch(SQLException se) {
- System.out.println("Unable to establish connection: " + se.getMessage());
- }
- <ResourceLink global="jdbc/datasource1" name="datasource1" type="javax.sql.DataSource"/>
Add Comment
Please, Sign In to add comment