Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection conn = null;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- Context initContext = new InitialContext();
- Context envContext = (Context) initContext.lookup("java:/comp/env");
- DataSource ds = (DataSource) envContext.lookup("jdbc/VINService");
- String sql = "SELECT ...";
- conn = ds.getConnection();
- stmt = conn.prepareStatement(sql);
- ...
- <resource-ref>
- <res-ref-name>jdbc/VINService</res-ref-name>
- <jndi-name>java:jdbc/VINService</jndi-name>
- <res-type>javax.sql.DataSource</res-type>
- </resource-ref>
- <resource-ref>
- <description>VINService</description>
- <res-ref-name>jdbc/VINService</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- <?xml version="1.0" encoding="UTF-8"?>
- <datasources>
- <local-tx-datasource>
- <jndi-name>jdbc/VINService</jndi-name>
- <connection-url>jdbc:mysql://url/db?autoReconnect=true</connection-url>
- <driver-class>com.mysql.jdbc.Driver</driver-class>
- <user-name>name</user-name>
- <password>password</password>
- <min-pool-size>5</min-pool-size>
- <max-pool-size>20</max-pool-size>
- <idle-timeout-minutes>0</idle-timeout-minutes>
- <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
- <check-valid-connection-sql>SELECT 1 FROM vehiclecache limit 1</check-valid-connection-sql>
- </local-tx-datasource>
- </datasources>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement