Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <Resources name="jdbc/murach" auth="Containter"
  4. driverClassName="com.mysql.jdbc.Driver"
  5. url="jdbc:mysql://localhost:3306/murach"
  6. username="root" password="root"
  7. maxActive="100" maxIdle="30" maxWait="10000"
  8. logAbandoned="true" removeAbandoned="true"
  9. removeAbandonedTimeout="60" type="javax.sql.DataSource" />
  10.  
  11. <ResourceLink name="jdbc/murach"
  12. global="jdbc/mydb"
  13. type="javax.sql.DataSource" />
  14.  
  15. package lars.data;
  16.  
  17. import java.sql.Connection;
  18. import java.sql.SQLException;
  19. import javax.naming.InitialContext;
  20. import javax.naming.NamingException;
  21. import javax.sql.DataSource;
  22.  
  23.  
  24. public class ConnectionPool {
  25. private static ConnectionPool pool = null;
  26. private static DataSource dataSource = null;
  27.  
  28. private ConnectionPool() {
  29. try {
  30. InitialContext ic = new InitialContext();
  31. dataSource = (DataSource) ic.lookup("java:/comp/env/jdbc/murach");
  32. System.out.print(dataSource);
  33. } catch (NamingException e) {
  34. System.out.println(e);
  35. }
  36. }
  37.  
  38. public static synchronized ConnectionPool getInstance() {
  39. if (pool == null) {
  40. pool = new ConnectionPool();
  41. }
  42. return pool;
  43. }
  44.  
  45. public Connection getConnection() {
  46. try {
  47. return dataSource.getConnection();
  48. } catch (SQLException e) {
  49. System.out.println(e);
  50. return null;
  51. }
  52. }
  53.  
  54. public void freeConnection(Connection c) {
  55. try {
  56. c.close();
  57. } catch (SQLException e) {
  58. System.out.println(e);
  59. }
  60. }
  61. }
  62.  
  63. <ResourceLink name="jdbc/murach"
  64. global="jdbc/murach"
  65. type="javax.sql.DataSource" />
  66.  
  67. <Resource name="jdbc/murach" ... />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement