Reputation: 876
I have class DBBase
defined as follow in my application:
public class DBBase {
public static void close(Statement stmt) {
try {
if (stmt != null) stmt.close();
} catch (Exception ex) {
logger.error("Exception:(", ex);
}
}
public static void close(ResultSet resultSet) {
try {
if (resultSet != null) resultSet.close();
} catch (Exception ex) {
logger.error("Exception:(", ex);
}
}
public static void close(Connection con) {
try {
if (con != null) con.close();
} catch (Exception ex) {
logger.error("Exception:(", ex);
}
}
public static void close(Object... closeable) {
for (Object obj : closeable) {
if (obj != null) {
if (obj instanceof Connection) close((Connection) obj);
else if (obj instanceof ResultSet) close((ResultSet) obj);
else if (obj instanceof Statement) close((Statement) obj);
}
}
}
}
When I call the close method DBBase.close(con, stmt, resSet)
from another class, everything works fine but when I call this method from a JSP
page I got the following error:
An error occurred at line: 20 in the jsp file: /admin/test.jsp
Generated servlet error:
The method close(Statement) in the type DBBase is not applicable for the arguments (Connection, Statement, ResultSet)
And this is my JSP page:
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="db.DBBase" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
Connection con = null;
Statement stmt = null;
ResultSet resSet = null;
try {
// Some code here
} catch (Exception ex) {
ex.printStackTrace();
} finally {
DBBase.close(con, stmt, resSet);
}
%>
<html>
<head>
<title>Test JSP File</title>
</head>
<body>
</body>
</html>
My JDK version is 1.7.0._51 with language level 7
What is the problem?
UPDATE
This is my server and jsp configs:
Server Version: Apache Tomcat/5.5.17
Servlet Version: 2.4
JSP Version: 2.0
Actually I have JBoss 4.0.4 GA
UPDATE
Regarding to @AlexC's comments I have to change my JBoss version to use varargs.
Upvotes: 1
Views: 283
Reputation: 1415
JSR-245 for JSP 2.1 defined usage of varargs in JSP and in Tomcat this was done during 7.x release cycle. (See http://alex-perevalov.livejournal.com/30156.html and https://wiki.apache.org/tomcat/Specifications )
In in web.xml (see http://tomcat.apache.org/tomcat-7.0-doc/jasper-howto.html ) you can specify the JSP version to support if you need to limit it.
Upgrading your app server to JSP 2.1 compatible one should allow varargs.
Upvotes: 1