Advertisement
Guest User

Untitled

a guest
Nov 12th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <Resource name="jdbc/kokosinjac"
  2.  
  3. auth="Container"
  4.  
  5. type="javax.sql.DataSource"
  6.  
  7. username="root"
  8.  
  9. password=""
  10.  
  11. driverClassName="org.mariadb.jdbc.Driver"
  12.  
  13. url="jdbc:mysql://[my_remote_ip]:3306//kokosinjac"
  14. (i have read somewhere that it is fine to leave mysql here)
  15.  
  16. maxActive="15"
  17.  
  18. maxIdle="3"/>
  19. </Context>
  20.  
  21. <resource-ref>
  22. <description>Database reference connection</description>
  23. <res-ref-name>jdbc/kokosinjac</res-ref-name>
  24. <res-type>javax.sql.DataSource</res-type>
  25. <res-auth>Container</res-auth>
  26. </resource-ref>
  27.  
  28. public class Connector {
  29.  
  30. private Context initCtx = null;
  31. private Context envCtx;
  32. private DataSource ds;
  33. public Connection con;
  34.  
  35.  
  36. public Connection getDbConnection () throws SQLException{
  37.  
  38.  
  39. try {
  40. Class.forName("org.mariadb.jdbc.Driver").newInstance();
  41.  
  42. initCtx = new InitialContext();
  43. envCtx = (Context) initCtx.lookup("java:comp/env");
  44. ds = (DataSource) envCtx.lookup("jdbc/kokosinjac");
  45.  
  46. con = ds.getConnection();
  47.  
  48. }catch (Exception ex){
  49. con.close();
  50. System.out.print("Could not establish connection to the Database");
  51. }
  52.  
  53. return con;}
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement