Advertisement
Guest User

Untitled

a guest
Jul 16th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. package com.example.crmapp;
  2. import java.sql.*;
  3.  
  4. import javax.sql.DataSource;
  5. import javax.naming.*;
  6.  
  7.  
  8. public class MySqlDAOFactory extends DAOFactory {
  9.  
  10. public static final String DRIVER = "com.mysql.jdbc.Driver";
  11. public static final String dbURL = "jdbc:mysql://localhost:3306/crmdb?autoReconnect=true&useSSL=false";
  12. private static final String user = "root";
  13. private static final String pass = "krut";
  14.  
  15. private static Connection conn = null;
  16. private static DataSource ds = null;
  17.  
  18. public static Connection createConnection() {
  19.  
  20. try {
  21. InitialContext ctx = new InitialContext();
  22. ds = (DataSource)ctx.lookup("java:jboss/datasources/crmdb");
  23. conn = ds.getConnection();
  24. } catch (NamingException e) {
  25. e.printStackTrace();
  26. } catch (SQLException ex) {
  27. ex.printStackTrace();
  28. }
  29.  
  30. return conn;
  31. }
  32.  
  33. @Override
  34. public CustomerDao getCustomerDAO() {
  35. return new CustomerDaoImpl();
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement