Skip navigation links

MySQL Forums :: Connector/JDBC and Java :: Insert into a table using Direct JDBC with JSP on Tomcat


Advanced Search

Insert into a table using Direct JDBC with JSP on Tomcat
Posted by: Dan Daughtery ()
Date: December 02, 2005 09:32AM

I have successfully gotten a mysql Select statement running using "mysql-connector-java-3.0.8-stable-bin.jar" (It's sitting in common\lib) but when I try to use the following code to run an insert SQL statement I get an error that says:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 13 in the jsp file: /DBProcessPage.jsp
Generated servlet error:
SQLExeception cannot be resolved to a type

An error occurred at line: 13 in the jsp file: /DBProcessPage.jsp
Generated servlet error:
e cannot be resolved


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


THE CODE FOLLOWS



<%@ page import="java.net.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
Connection conn = null;

PreparedStatement stmt = null;


try{
Class c = Class.forName("com.mysql.jdbc.Driver");
//Class c = Class.forName("com.mysql.jdbc.Driver");


}
catch (SQLException e) {
System.out.println("Unable to load driver.");
e.printStackTrace();
}
try{

conn = DriverManager.getConnection("jdbc:mysql://localhost/test");

}
catch (SQLException e) {
System.out.println("Exception: ");
}


try {
//String queryText = "insert into tblQuestions (quest, questStatus) values('Is this working?', 'New')";


stmt = conn.prepareStatement("INSERT INTO tblQuestions (quest, questStatus) VALUES(?,?)");
stmt.setString(1, request.getParameter("newFAQ"));
stmt.setString(2, request.getParameter("status"));
stmt.executeUpdate();
stmt.close();
conn.close();
}
catch (SQLExeception e){
System.out.println("Error occured " + e);
}
finally {
try{
if (stmt != null)
stmt.close();
}catch (SQLException e) {}
try {
if(conn != null)
conn.close();
} catch (SQLException e) {}
}
%>





<h1>Processing Data</h1>


</body>
</html>



Any help would be appreciated.

Options: ReplyQuote


Subject Written By Posted
Insert into a table using Direct JDBC with JSP on Tomcat Dan Daughtery 12/02/2005 09:32AM
Re: Insert into a table using Direct JDBC with JSP on Tomcat k.arul kumar 03/12/2006 11:38PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.