daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Sep 22nd, 2016 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version='1.0' encoding='utf-8'?>
  2.  <Context>
  3.  <Resource
  4.       name="jdbc/library"
  5.       auth="Container"
  6.       description="DB Connection"
  7.       username="root"
  8.       password="root"
  9.       driverClassName="com.mysql.jdbc.Driver"
  10.       url="jdbc:mysql://localhost:3306/library"
  11.       maxActive="10"
  12.       maxIdle="3"
  13.       maxWait="100"
  14.       factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
  15.       type="javax.sql.DataSource"></Resource>
  16.  </Context>
  17.    
  18. <resource-ref>
  19.   <description>DB Connection</description>
  20.   <res-ref-name>jdbc/library</res-ref-name>
  21.   <res-type>javax.sql.DataSource</res-type>
  22.   <res-auth>Container</res-auth>
  23. </resource-ref>
  24.    
  25. public void check() {
  26.     try {
  27.         InitialContext initialContext = new InitialContext();
  28.         DataSource dataSource =    (DataSource)initialContext.lookup("java:comp/env/jdbc/library");
  29.         Connection connection = dataSource.getConnection();
  30.         Statement statement = connection.createStatement();
  31.         ResultSet resultSet = statement.executeQuery("SELECT * FROM book");
  32.         System.out.println(resultSet.next());
  33.     } catch (NamingException e) {
  34.         e.printStackTrace();
  35.     } catch (SQLException e) {
  36.         e.printStackTrace();
  37.     }
  38.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top