Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Resource name="jdbc/kokosinjac"
- auth="Container"
- type="javax.sql.DataSource"
- username="root"
- password=""
- driverClassName="org.mariadb.jdbc.Driver"
- url="jdbc:mysql://[my_remote_ip]:3306//kokosinjac"
- (i have read somewhere that it is fine to leave mysql here)
- maxActive="15"
- maxIdle="3"/>
- </Context>
- <resource-ref>
- <description>Database reference connection</description>
- <res-ref-name>jdbc/kokosinjac</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- public class Connector {
- private Context initCtx = null;
- private Context envCtx;
- private DataSource ds;
- public Connection con;
- public Connection getDbConnection () throws SQLException{
- try {
- Class.forName("org.mariadb.jdbc.Driver").newInstance();
- initCtx = new InitialContext();
- envCtx = (Context) initCtx.lookup("java:comp/env");
- ds = (DataSource) envCtx.lookup("jdbc/kokosinjac");
- con = ds.getConnection();
- }catch (Exception ex){
- con.close();
- System.out.print("Could not establish connection to the Database");
- }
- return con;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement