users@glassfish.java.net

Re: Cannot use JDBC Realm with MySQL Database

From: <glassfish_at_javadesktop.org>
Date: Sat, 03 Nov 2007 12:53:23 PST

If you want to test your JNDI JDBC-Rsource use this servlet method as a reference:

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestDBServlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("Servlet TestDBServlet at " + request.getContextPath() + " ");
        try {
            InitialContext ctx = new InitialContext();
            DataSource ds = (DataSource) ctx.lookup("jdbc/YourDataSource");
            Connection connection = ds.getConnection();
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery("select " + "usertable.userid,password,groupid " + "from usertable,grouptable where usertable.userid=grouptable.userid");
            while(rs.next()) {
                out.println("user, pw, group: " + rs.getString(1) + ", " + rs.getString(2) + ", " + rs.getString(3) + " ");
            }
        } catch (Exception ex) {
            out.println("Got an Exception: " + ex);
        } out.println("</body>");
        out.println("</html>");
        out.close();
    }
[Message sent by forum member 'zebhed' (zebhed)]

http://forums.java.net/jive/thread.jspa?messageID=243680