Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <Resources name="jdbc/murach" auth="Containter"
- driverClassName="com.mysql.jdbc.Driver"
- url="jdbc:mysql://localhost:3306/murach"
- username="root" password="root"
- maxActive="100" maxIdle="30" maxWait="10000"
- logAbandoned="true" removeAbandoned="true"
- removeAbandonedTimeout="60" type="javax.sql.DataSource" />
- <ResourceLink name="jdbc/murach"
- global="jdbc/mydb"
- type="javax.sql.DataSource" />
- package lars.data;
- import java.sql.Connection;
- import java.sql.SQLException;
- import javax.naming.InitialContext;
- import javax.naming.NamingException;
- import javax.sql.DataSource;
- public class ConnectionPool {
- private static ConnectionPool pool = null;
- private static DataSource dataSource = null;
- private ConnectionPool() {
- try {
- InitialContext ic = new InitialContext();
- dataSource = (DataSource) ic.lookup("java:/comp/env/jdbc/murach");
- System.out.print(dataSource);
- } catch (NamingException e) {
- System.out.println(e);
- }
- }
- public static synchronized ConnectionPool getInstance() {
- if (pool == null) {
- pool = new ConnectionPool();
- }
- return pool;
- }
- public Connection getConnection() {
- try {
- return dataSource.getConnection();
- } catch (SQLException e) {
- System.out.println(e);
- return null;
- }
- }
- public void freeConnection(Connection c) {
- try {
- c.close();
- } catch (SQLException e) {
- System.out.println(e);
- }
- }
- }
- <ResourceLink name="jdbc/murach"
- global="jdbc/murach"
- type="javax.sql.DataSource" />
- <Resource name="jdbc/murach" ... />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement