| | |
error while retroeving data from mqsql database
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 38
Reputation:
Solved Threads: 0
Hi;
The below jsp page is compiling fine but executing it shows error asjavax.servlet.ServletException: java.sql.SQLException: Column 'Total' not found.
Thansk in advance
Regards
Haresh
The below jsp page is compiling fine but executing it shows error asjavax.servlet.ServletException: java.sql.SQLException: Column 'Total' not found.
<%--
Document : evaluationeventtable
Created on : Jul 24, 2008, 6:52:37 PM
Author : user1
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language ="java" %>
<%@ page import="java.sql.*, javax.sql.*, javax.naming.*,java.io.*,java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Table-Data</title>
</head>
<body>
<% int QNO;
String ID=request.getParameter("id");
out.println(ID);
String EVENTID=request.getParameter("event");
out.println(EVENTID);
Connection connection = null;
Statement st = null;
Statement st1 = null;
Statement st2 = null;
Statement st3 = null;
Statement st4 = null;
Statement st5 = null;
ResultSet rs= null;
ResultSet rs1= null;
ResultSet rs2= null;
ResultSet rs3= null;
ResultSet rs4= null;
ResultSet rs5= null;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mynewdatabase","root", "root123");
st5=con.createStatement();
int count=0;
try {
rs5=st5.executeQuery("select count(*) from Final where Eventid='"+EVENTID+"'");
while(rs5.next())
{count=rs5.getInt(1);
out.println(count);
}
} finally
{
if (rs5 != null)
{
rs5.close();
rs5 = null;
}
if (st5 != null)
{
st5.close();
st5 = null;
}
}
st=con.createStatement();
try {
for( QNO=1;QNO<=count;QNO++);
rs = st.executeQuery("SELECT * FROM Questionbank where Questionid='"+ID+"'");
while ( rs.next() )
{
%>
<tr>
<input type="hidden" name="Qserino" value="<%=rs.getString("qserialno")%>"/>
<td colspan="5"><b>Question:</b>
<%=rs.getString("questionname")%>
</td>
</tr>
<%
st1=con.createStatement();
try {
rs1=st1.executeQuery("select count(*) as Total from final where questionid='"+ID+"'and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='A'");
while(rs1.next())
{
%>
<tr>
<td colspan="5"><b>No. of A:</b>
<%=rs.getString("Total")%>
</td>
</tr>
<%
}
} finally
{
if (rs1!= null)
{
rs1.close();
rs1= null;
}
if (st1 != null)
{
st1.close();
st1 = null;
}
}
%>
<%
st2=con.createStatement();
try {
rs2=st2.executeQuery("select count(*) as Total1 from final where questionid='"+ID+"' and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='B'");
while(rs2.next())
{
%>
<tr>
<td colspan="5"><b>No. of B:</b>
<%=rs.getString("Total1")%>
</td>
</tr>
<%
}
} finally
{
if (rs2!= null)
{
rs2.close();
rs2= null;
}
if (st1 != null)
{
st1.close();
st1 = null;
}
}
%>
<%
st3=con.createStatement();
try {
rs3=st3.executeQuery("select count(*) as Total2 from final where questionid='"+ID+"' and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='C'");
while(rs3.next())
{
%>
<tr>
<td colspan="5"><b>No. of C:</b>
<%=rs.getString("Total2")%>
</td>
</tr>
<%
}
} finally
{
if (rs3!= null)
{
rs3.close();
rs3= null;
}
if (st3 != null)
{
st3.close();
st3 = null;
}
}
%>
<%
st4=con.createStatement();
try {
rs4=st4.executeQuery("select count(*) as Total3 from final where questionid='"+ID+"' and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='D'");
while(rs4.next())
{
%>
<tr>
<td colspan="5"><b>No. of D:</b>
<%=rs.getString("Total3")%>
</td>
</tr>
<%
}
} finally
{
if (rs4!= null)
{
rs4.close();
rs4= null;
}
if (st4 != null)
{
st4.close();
st4 = null;
}
}
%>
<%
}
} finally
{
if (rs != null)
{
rs.close();
rs = null;
}
if (st != null)
{
st.close();
st = null;
}
}
%>
</body></html>Regards
Haresh
Did you mean maybe rs1.getString("Total"), seeing as how that statement seems to be in the rs1.next() while loop.
Also, you definately should not be doing this stuff as scriptlets in a JSP. This is a maintenance nightmare.
Also, you definately should not be doing this stuff as scriptlets in a JSP. This is a maintenance nightmare.
Last edited by masijade; Jul 25th, 2008 at 6:58 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jun 2008
Posts: 38
Reputation:
Solved Threads: 0
Hi;
with updated code, I am getting the value of four count query as zero.
and here is an output:
Any suggestion is highly appreciated.
Thanks and Regards
Haresh
with updated code, I am getting the value of four count query as zero.
JSP Syntax (Toggle Plain Text)
<%-- Document : evaluationeventtable Created on : Jul 24, 2008, 6:52:37 PM Author : user1 --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ page language ="java" %> <%@ page import="java.sql.*, javax.sql.*, javax.naming.*,java.io.*,java.util.*" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Table-Data</title> </head> <body> <% int QNO; String ID=request.getParameter("id"); out.println(ID); String EVENTID=request.getParameter("event"); out.println(EVENTID); Connection connection = null; Statement st = null; Statement st1 = null; Statement st2 = null; Statement st3 = null; Statement st4 = null; Statement st5 = null; ResultSet rs= null; ResultSet rs1= null; ResultSet rs2= null; ResultSet rs3= null; ResultSet rs4= null; ResultSet rs5= null; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mynewdatabase","root", "root123"); st5=con.createStatement(); int count=0; try { rs5=st5.executeQuery("select count(*) from Final where Eventid='"+EVENTID+"'"); while(rs5.next()) {count=rs5.getInt(1); out.println(count); } } finally { if (rs5 != null) { rs5.close(); rs5 = null; } if (st5 != null) { st5.close(); st5 = null; } } st=con.createStatement(); try { rs = st.executeQuery("SELECT * FROM Questionbank where Questionid='"+ID+"'"); while ( rs.next() ) { %> <table border="0"> <tr> <th><b>Question:</b></th><th><b>OPTION-A</b></th><th><b>OPTION-B</b></th><th><b>OPTION-C</b></th><th><b>OPTION-D</b></th></tr> <tr> <td> <%=rs.getString("questionname")%></td> </tr> <% for( QNO=1;QNO<=count;QNO++); st1=con.createStatement(); try { rs1=st1.executeQuery("select count(*) as Total from final where questionid='"+ID+"'and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='A'"); while(rs1.next()) { %> <td><b> <%=rs1.getString("Total")%></b> </td> <% } } finally { if (rs1!= null) { rs1.close(); rs1= null; } if (st1 != null) { st1.close(); st1 = null; } } %> <% st2=con.createStatement(); try { rs2=st2.executeQuery("select count(*) as Total1 from final where questionid='"+ID+"' and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='B'"); while(rs2.next()) { %> <td><b> <%=rs2.getString("Total1")%></b> </td> <% } } finally { if (rs2!= null) { rs2.close(); rs2= null; } if (st1 != null) { st1.close(); st1 = null; } } %> <% st3=con.createStatement(); try { rs3=st3.executeQuery("select count(*) as Total2 from final where questionid='"+ID+"' and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='C'"); while(rs3.next()) { %> <td><b> <%=rs3.getString("Total2")%></b> </td> <% } } finally { if (rs3!= null) { rs3.close(); rs3= null; } if (st3 != null) { st3.close(); st3 = null; } } %> <% st4=con.createStatement(); try { rs4=st4.executeQuery("select count(*) as Total3 from final where questionid='"+ID+"' and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='D'"); while(rs4.next()) { %> <td><b> <%=rs4.getString("Total3")%></b></td> </tr></table> <% } } finally { if (rs4!= null) { rs4.close(); rs4= null; } if (st4 != null) { st4.close(); st4 = null; } } %> <% } } finally { if (rs != null) { rs.close(); rs = null; } if (st != null) { st.close(); st = null; } } %> </body></html>
and here is an output:
JSP Syntax (Toggle Plain Text)
6 1 22 Question: OPTION-A OPTION-B OPTION-C OPTION-D How difficult did you find the course? 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D How much outside work per week (excluding time spent in attending lectures) did the course entail? 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D How easily were the books and articles recommended in the class available in the library? 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D How useful did you find the suggested readings? 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D Do you think a sufficient number of quizzes/exams were given? 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D How helpful were the quizzes/exams? 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D How fair were the exams (that counted towards your grade) testing your knowledge of the course material? 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D Was classroom participation encouraged? 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D Contents of the course 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D How far was your understanding of the subject increased after taking this course? 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D Impacts of the course 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D Does it prepare you for research in that field? 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D Should the same course be given to others (Assume you are again in the same batch). 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D Knowledge of the instructor related to the course 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D Preparation of the instructor 0 0 0 0 Question: OPTION-A OPTION-B OPTION-C OPTION-D Preparation of the instructor 0 0 0 0
Thanks and Regards
Haresh
Last edited by peter_budo; Jul 25th, 2008 at 9:04 am. Reason: replacing [tex] tag with [code] for readibilty reasons
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
•
•
No point to repeat that, this guy completely ignore that for last two weeks from me. Another hopeless case to bang on...
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
That code just look awful ! ! !
So much nicer if data would be retrieved from DB in servlet, stored in the bean and with session passed to JSP where everything would be displayed with few lines of necessary scriplet
So much nicer if data would be retrieved from DB in servlet, stored in the bean and with session passed to JSP where everything would be displayed with few lines of necessary scriplet
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
> So much nicer if data would be retrieved from DB in servlet,
Not to mention that actually *nothing* should go in servlet except the processing of request parameters / attributes and invocation of the actual business logic components. This helps in ensuring that you don't repeat yourself when the view changes. E.g. from a web based application to a swing based application.
Not to mention that actually *nothing* should go in servlet except the processing of request parameters / attributes and invocation of the actual business logic components. This helps in ensuring that you don't repeat yourself when the view changes. E.g. from a web based application to a swing based application.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
![]() |
Other Threads in the JSP Forum
- Previous Thread: can any one send me a jsp source code of an e-banking project
- Next Thread: Learning JSP- Bad tutorial.
Views: 1017 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for JSP
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient project read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






