Reputation: 1
I am having trouble with this exception:
type Exception report
message An exception occurred processing JSP page /home/index.jsp at line 54
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /home/index.jsp at line 54
51: <link rel="shortcut icon" href="../assets/ico/favicon.png">
52: <style type="text/css">
53: <%
54: HashMap<String,Object> background = com.controlj.green.definitions.Utilities.getBackground();
55: String background_image = "";
56: if(!background.isEmpty()){
57: background_image = "data:image/png;base64," + background.get("bytes").toString();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
com.controlj.green.servlets.Index.doGet(Index.java:51)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
javax.servlet.ServletException: java.lang.IncompatibleClassChangeError: Found class com.mysql.jdbc.Statement, but interface was expected
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.home.index_jsp._jspService(index_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
com.controlj.green.servlets.Index.doGet(Index.java:51)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.lang.IncompatibleClassChangeError: Found class com.mysql.jdbc.Statement, but interface was expected
com.controlj.green.definitions.Utilities.getBackground(Utilities.java:172) org.apache.jsp.home.index_jsp._jspService(index_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
com.controlj.green.servlets.Index.doGet(Index.java:51)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.
Apache Tomcat/7.0.42
I really don't know what's wrong in line 54.
It is apparently calling this : com.controlj.green.definitions.Utilities.getBackground();
which is :
import java.util.*;
public static HashMap<String,Object> getBackground() throws SQLException, ClassNotFoundException, IOException {
if(establishConnection()){
Statement st = (Statement) con.createStatement();
rs = st.executeQuery("select bytes from connection_string");
ResultSetMetaData md = (ResultSetMetaData) rs.getMetaData();
int columns = md.getColumnCount();
HashMap<String,Object> list = new HashMap<String,Object>();
if (rs.next()) {
for(int i=1; i<=columns; ++i){
list.put(md.getColumnName(i),rs.getObject(i));
}
}
return list;
}else{
return null;
}
}
What could be wrong in this?
Thanks.
Upvotes: 0
Views: 2341
Reputation: 8217
From the stacktrace,
root cause javax.servlet.ServletException: java.lang.IncompatibleClassChangeError: Found class
com.mysql.jdbc.Statement, but interface was expected
Why have you cast the statement
class here ,
Statement st = (Statement) con.createStatement();
it needs to be,
Statement st =con.createStatement();
Expecting con
to be connection object
Update:
As per the error you have shared its the wrong imports ,
Wrong classes
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
should be
import java.sql.Connection;
import java.sql.Statement;
Hope this helps
Upvotes: 1
Reputation: 8956
I dont think we need casting as you did here
Statement st = (Statement) con.createStatement();
as long as con
is an object of type java.sql.Connection
or may be you are using some older version of mysql-connector.jar
trying replacing it with some newer version and import the connection statements again
Upvotes: 0
Reputation: 13481
From where are you getting the connection?. Global variable?, I would try to changes your prepared statement for something like this. I dont know if you´re controlling the exception in some point to close the connection by the way.
PreparedStatement ps = null;
try{
ps = conn.prepareStatement("select bytes from connection_string");
ps.executeQuery();
} catch(Exception ex){
System.out.println("");
} finally {
try{
if(ps!=null){
ps.close();
}
if(conn!=null){
conn.close();
}
} catch(Exception ex){
System.out.println("");
}
}
Upvotes: 0
Reputation: 5868
What is con in
Statement st = (Statement) con.createStatement();
Where does is come from. And anyway you donot need a cast to Statement.
Upvotes: 0