•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 427,458 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,563 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 7098 | Replies: 4 | Solved
![]() |
•
•
Join Date: Sep 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Hi,
I am trying to make a simple jsp program which eneters data eneterd by user in an html form called main.html.
This is the code for main.html
[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Benthic_query </TITLE>
</HEAD>
<BODY>
<form METHOD = POST ACTION="dataConnection.jsp">
Enter the name of the new table: <input type = text name = table_name size= 30>
<br>
Enter the number of the table: <input type = text name=table_number size=10>
<p> <input type = Submit>
</BODY>
</HTML>
And here is the code for dataConnection:
[code]
<%@ page import="java.sql.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%
Connection conn = null;
try
{
String query = "insert into benthic_query values('"+name+"', '"+number+"')";
String userName = "root";
String password = "abc";
String url = "jdbc:mysql://localhost/test";
String name= request.getParameter("table_name");
String number = request.getParameter("table_number");
Class.forName ("com.mysql.jdbc.Driver").newInstance(); //Loading the driver
conn = DriverManager.getConnection(url, userName, password); //connect the appropriate driver to the database
System.out.println("Connection opened successfully");
Statement stmt = conn.createStatement (); //Statement object sends the SQL statement to the DBMS
stmt.executeUpdate ("query"); //executeQuery will return back some rows, executeUpdate does not return any rows
stmt.close();
System.out.println("Connection opened successfully");
}
catch (Exception e)
{
System.err.println("Cannot connect to the database");
}
finally
{
if(conn != null)
{
try
{
conn.close();
System.out.println("Database connection closed successfully");
}
catch (Exception e)
{
}
}
}
// response.sendRedirect("success.htm");
%>
<html>
<body>
<p> <a href = "thanks.html">CONTINUE </a> </p>
</html>
</body>
And I am getting the following error as soon as I hit the submit button in main.html
exception org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 7 in the jsp file: /sjagwani/dataConnection.jsp
Generated servlet error:C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\_\org\apache\jsp\sjagwani\dataConnection_jsp.java:58:
cannot find symbol
symbol : variable name
location: class org.apache.jsp.sjagwani.dataConnection_jsp
String query = "insert into benthic_query values('"+name+"', '"+number+"')";
^An error occurred at line: 7 in the jsp file: /sjagwani/dataConnection.jspGenerated servlet error:C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\_\org\apache\jsp\sjagwani\dataConnection_jsp.java:58: cannot find symbol
symbol : variable number
location: class org.apache.jsp.sjagwani.dataConnection_jsp
String query = "insert into benthic_query values('"+name+"', '"+number+"')";
^2errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332) org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412) org.apache.jasper.compiler.Compiler.compile(Compiler.java:472) org.apache.jasper.compiler.Compiler.compile(Compiler.java:451) org.apache.jasper.compiler.Compiler.compile(Compiler.java:439) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)Can someone please tell me where am I going worng.Thanks,
I am trying to make a simple jsp program which eneters data eneterd by user in an html form called main.html.
This is the code for main.html
[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Benthic_query </TITLE>
</HEAD>
<BODY>
<form METHOD = POST ACTION="dataConnection.jsp">
Enter the name of the new table: <input type = text name = table_name size= 30>
<br>
Enter the number of the table: <input type = text name=table_number size=10>
<p> <input type = Submit>
</BODY>
</HTML>
And here is the code for dataConnection:
[code]
<%@ page import="java.sql.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%
Connection conn = null;
try
{
String query = "insert into benthic_query values('"+name+"', '"+number+"')";
String userName = "root";
String password = "abc";
String url = "jdbc:mysql://localhost/test";
String name= request.getParameter("table_name");
String number = request.getParameter("table_number");
Class.forName ("com.mysql.jdbc.Driver").newInstance(); //Loading the driver
conn = DriverManager.getConnection(url, userName, password); //connect the appropriate driver to the database
System.out.println("Connection opened successfully");
Statement stmt = conn.createStatement (); //Statement object sends the SQL statement to the DBMS
stmt.executeUpdate ("query"); //executeQuery will return back some rows, executeUpdate does not return any rows
stmt.close();
System.out.println("Connection opened successfully");
}
catch (Exception e)
{
System.err.println("Cannot connect to the database");
}
finally
{
if(conn != null)
{
try
{
conn.close();
System.out.println("Database connection closed successfully");
}
catch (Exception e)
{
}
}
}
// response.sendRedirect("success.htm");
%>
<html>
<body>
<p> <a href = "thanks.html">CONTINUE </a> </p>
</html>
</body>
And I am getting the following error as soon as I hit the submit button in main.html
exception org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 7 in the jsp file: /sjagwani/dataConnection.jsp
Generated servlet error:C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\_\org\apache\jsp\sjagwani\dataConnection_jsp.java:58:
cannot find symbol
symbol : variable name
location: class org.apache.jsp.sjagwani.dataConnection_jsp
String query = "insert into benthic_query values('"+name+"', '"+number+"')";
^An error occurred at line: 7 in the jsp file: /sjagwani/dataConnection.jspGenerated servlet error:C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\_\org\apache\jsp\sjagwani\dataConnection_jsp.java:58: cannot find symbol
symbol : variable number
location: class org.apache.jsp.sjagwani.dataConnection_jsp
String query = "insert into benthic_query values('"+name+"', '"+number+"')";
^2errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332) org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412) org.apache.jasper.compiler.Compiler.compile(Compiler.java:472) org.apache.jasper.compiler.Compiler.compile(Compiler.java:451) org.apache.jasper.compiler.Compiler.compile(Compiler.java:439) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)Can someone please tell me where am I going worng.Thanks,
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation:
Rep Power: 18
Solved Threads: 199
You do I hope realise that it's very bad practice to do such things in a JSP?
Send the form submit to a servlet and do it there, then send the result of that operation back to a JSP for display.
Send the form submit to a servlet and do it there, then send the result of that operation back to a JSP for display.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access avatar backup breach broadband code combo crime daniweb data data protection data transfer database design drive dropdownlist forensics government hacker hard hardware hitachi ibm internet linux medicine module net news normalization reuse security server sql storage survey terabyte web wikipedia
- how to insert data into the database in vb.net using textfields. (VB.NET)
- Problem with retrieving data from access 2003 (Visual Basic 4 / 5 / 6)
- inserting data (ColdFusion)
- Problem adding registration data to mysql database (JSP)
- Please help(Problem in insertion data to database) (JSP)
- Inserting Data into Access Database (Java)
- Unable to insert data into SQL Database (ASP)
Other Threads in the JSP Forum
- Previous Thread: jsp
- Next Thread: How to Execute JSP FIle



Linear Mode