Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- inside server.xml -->
- <Context path="/myApp">
- <Resource name="jdbc/testdb" auth="Container"
- type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
- url="jdbc:postgresql://localhost:5432/testdb"
- username="postgres" password="" maxActive="20" maxIdle="10" maxWait="-1"
- />
- </Context>
- <!-- inside web.xml -->
- <resource-ref>
- <description>postgreSQL Datasource example</description>
- <res-ref-name>jdbc/testdb</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- /* The JSP code */
- <%@ page import="java.sql.*, javax.sql.*, javax.naming.*"%>
- <%
- InitialContext cxt = new InitialContext();
- if ( cxt == null ) {
- throw new Exception("Uh oh -- no context!");
- }
- DataSource ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/testdb" );
- if ( ds == null ) {
- throw new Exception("Data source not found!");
- }
- try {
- Connection con = ds.getConnection();
- } catch (Exception e) {
- out.println(e.getMessage());
- }
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement