Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version='1.0' encoding='utf-8'?>
- <Context>
- <resource
- name="jdbc/library"
- auth="Container"
- description="DB Connection"
- username="root"
- password="root"
- driverClassName="com.mysql.jdbc.Driver"
- url="jdbc:mysql://localhost:3306/library"
- maxActive="10"
- maxIdle="3"
- maxWait="100"
- factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
- type="javax.sql.DataSource"></resource>
- </Context>
- <resource-ref>
- <description>DB Connection</description>
- <res-ref-name>jdbc/library</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- public void check() {
- try {
- InitialContext initialContext = new InitialContext();
- DataSource dataSource = (DataSource)initialContext.lookup("java:comp/env/jdbc/library");
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery("SELECT * FROM book");
- System.out.println(resultSet.next());
- } catch (NamingException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment