Code example for DataSource

Methods: getConnection

0
        PrintWriter out = response.getWriter();
        out.println("Hello World");
 
        InitialContext jndiContext = new InitialContext();
        DataSource ds = (DataSource) jndiContext.lookup("java:comp/env/jdbc/connPool");
        Connection conn = ds.getConnection("root", "password");
        Statement stmt = conn.createStatement();
        boolean results = stmt.execute("SELECT NOW();");
        out.println("<br>results: " + results + "<br>");
    } 
 
}