I just noticed that the DelegatingResultSet object handed by Tomcat
sports a slew of abstract methods even though the class itself is
not declared abstract. In Tomcat 7.0.x there are only 2 such methods:
the two getObject methods taking a Class as second argument, which are
also the only two methods marked as 1.7 level in the Javadocs, but for
Tomcat 6.0.x there are lots of them, including the isClosed method, all
of them marked 1.6 level AFAICT.

This seems very wrong, esp. the fact the DelegatingResultSet class is
not marked as abstract. I have attached a test servlet that demonstrates
the behaviour: install it and call http://localhost:8080/test1/get
(or whatever is your Tomcat server location). I tested against 6.0.30
and 7.0.27. Can somebody comment?

Thanks,

-- O.L.
package test1;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.*;

import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.DataSource;

public class Test1Servlet extends HttpServlet {

    private DataSource dataSource;

    @Override
    public void init() throws ServletException {
        dataSource = getDataSource();
    }

    private DataSource getDataSource() throws ServletException {
        try {
            Context ctx = new InitialContext();
            return (DataSource)ctx.lookup("java:comp/env/jdbc/Test1Database"); }
        catch (NamingException e) {
            // aborting servlet initialization
            throw new UnavailableException("getDataSource error", -1); }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        ServletContext ctx = getServletContext();
        try {
            Connection conn = dataSource.getConnection();
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT 1, 2, 3");
            conn.close();
            resp.setStatus(HttpServletResponse.SC_OK);
            PrintWriter w = resp.getWriter();
            Class<?> klass = rs.getClass();
            w.println("ResultSet class:");
            w.println("  " + Modifier.toString(klass.getModifiers()) + " " + 
klass.getName());
            try {
                w.println("isClosed() method signature:");
                w.println("  " + klass.getMethod("isClosed")); }
            catch (NoSuchMethodException e) {
                w.println("isClosed() method not found"); }
            w.println("abstract methods:");
            for (Method m : klass.getMethods()) {
                if (Modifier.isAbstract(m.getModifiers()))
                    w.println("  " + m); }
            w.flush();
            w.close(); }
        catch (SQLException e) {
            ctx.log("== query error");
            e.printStackTrace(); }
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to