943,871 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 1297
  • JSP RSS
Jul 25th, 2008
0

error while retroeving data from mqsql database

Expand Post »
Hi;
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>
Thansk in advance
Regards
Haresh
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008
Jul 25th, 2008
0

Re: error while retroeving data from mqsql database

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.
Last edited by masijade; Jul 25th, 2008 at 6:58 am.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jul 25th, 2008
0

Re: error while retroeving data from mqsql database

Hi;
with updated code, I am getting the value of four count query as zero.
JSP Syntax (Toggle Plain Text)
  1. <%--
  2. Document : evaluationeventtable
  3. Created on : Jul 24, 2008, 6:52:37 PM
  4. Author : user1
  5. --%>
  6.  
  7. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  8. <%@ page language ="java" %>
  9. <%@ page import="java.sql.*, javax.sql.*, javax.naming.*,java.io.*,java.util.*" %>
  10. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  11. "http://www.w3.org/TR/html4/loose.dtd">
  12.  
  13. <html>
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  16. <title>Table-Data</title>
  17. </head>
  18. <body>
  19. <% int QNO;
  20. String ID=request.getParameter("id");
  21. out.println(ID);
  22. String EVENTID=request.getParameter("event");
  23. out.println(EVENTID);
  24. Connection connection = null;
  25. Statement st = null;
  26. Statement st1 = null;
  27. Statement st2 = null;
  28. Statement st3 = null;
  29. Statement st4 = null;
  30. Statement st5 = null;
  31. ResultSet rs= null;
  32. ResultSet rs1= null;
  33. ResultSet rs2= null;
  34. ResultSet rs3= null;
  35. ResultSet rs4= null;
  36. ResultSet rs5= null;
  37.  
  38. Class.forName("com.mysql.jdbc.Driver");
  39. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mynewdatabase","root", "root123");
  40.  
  41. st5=con.createStatement();
  42. int count=0;
  43. try {
  44. rs5=st5.executeQuery("select count(*) from Final where Eventid='"+EVENTID+"'");
  45.  
  46. while(rs5.next())
  47. {count=rs5.getInt(1);
  48. out.println(count);
  49. }
  50.  
  51. } finally
  52. {
  53. if (rs5 != null)
  54. {
  55. rs5.close();
  56. rs5 = null;
  57. }
  58. if (st5 != null)
  59. {
  60. st5.close();
  61. st5 = null;
  62. }
  63.  
  64. }
  65. st=con.createStatement();
  66.  
  67. try {
  68.  
  69.  
  70. rs = st.executeQuery("SELECT * FROM Questionbank where Questionid='"+ID+"'");
  71.  
  72. while ( rs.next() )
  73. {
  74.  
  75. %>
  76. <table border="0">
  77. <tr>
  78. <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>
  79. <tr> <td> <%=rs.getString("questionname")%></td>
  80.  
  81. </tr>
  82.  
  83. <%
  84. for( QNO=1;QNO<=count;QNO++);
  85. st1=con.createStatement();
  86. try {
  87. rs1=st1.executeQuery("select count(*) as Total from final where questionid='"+ID+"'and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='A'");
  88.  
  89. while(rs1.next())
  90. {
  91. %>
  92.  
  93. <td><b>
  94. <%=rs1.getString("Total")%></b>
  95. </td>
  96.  
  97. <%
  98.  
  99. }
  100.  
  101. } finally
  102. {
  103. if (rs1!= null)
  104. {
  105. rs1.close();
  106. rs1= null;
  107. }
  108. if (st1 != null)
  109. {
  110. st1.close();
  111. st1 = null;
  112. }
  113.  
  114. }
  115. %>
  116. <%
  117. st2=con.createStatement();
  118. try {
  119. rs2=st2.executeQuery("select count(*) as Total1 from final where questionid='"+ID+"' and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='B'");
  120.  
  121. while(rs2.next())
  122. {
  123. %>
  124.  
  125. <td><b>
  126. <%=rs2.getString("Total1")%></b>
  127. </td>
  128.  
  129. <%
  130. }
  131.  
  132. } finally
  133. {
  134. if (rs2!= null)
  135. {
  136. rs2.close();
  137. rs2= null;
  138. }
  139. if (st1 != null)
  140. {
  141. st1.close();
  142. st1 = null;
  143. }
  144. }
  145. %>
  146. <%
  147. st3=con.createStatement();
  148. try {
  149. rs3=st3.executeQuery("select count(*) as Total2 from final where questionid='"+ID+"' and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='C'");
  150.  
  151. while(rs3.next())
  152. {
  153. %>
  154.  
  155. <td><b>
  156. <%=rs3.getString("Total2")%></b>
  157. </td>
  158.  
  159. <%
  160. }
  161.  
  162. } finally
  163. {
  164. if (rs3!= null)
  165. {
  166. rs3.close();
  167. rs3= null;
  168. }
  169. if (st3 != null)
  170. {
  171. st3.close();
  172. st3 = null;
  173. }
  174.  
  175. }
  176. %>
  177. <%
  178. st4=con.createStatement();
  179. try {
  180. rs4=st4.executeQuery("select count(*) as Total3 from final where questionid='"+ID+"' and Eventid='"+EVENTID+"'and Qserialno='"+QNO+"'and Answer='D'");
  181.  
  182. while(rs4.next())
  183. {
  184. %>
  185.  
  186. <td><b>
  187. <%=rs4.getString("Total3")%></b></td> </tr></table>
  188.  
  189. <%
  190. }
  191.  
  192. } finally
  193. {
  194. if (rs4!= null)
  195. {
  196. rs4.close();
  197. rs4= null;
  198. }
  199. if (st4 != null)
  200. {
  201. st4.close();
  202. st4 = null;
  203. }
  204. }
  205. %>
  206. <%
  207. }
  208.  
  209. } finally
  210. {
  211. if (rs != null)
  212. {
  213. rs.close();
  214. rs = null;
  215. }
  216. if (st != null)
  217. {
  218. st.close();
  219. st = null;
  220. }
  221.  
  222. }
  223. %>
  224.  
  225.  
  226. </body></html>

and here is an output:
JSP Syntax (Toggle Plain Text)
  1. 6 1 22 Question: OPTION-A OPTION-B OPTION-C OPTION-D
  2. How difficult did you find the course?
  3. 0 0 0 0
  4. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  5. How much outside work per week (excluding time spent in attending lectures) did the course entail?
  6. 0 0 0 0
  7. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  8. How easily were the books and articles recommended in the class available in the library?
  9. 0 0 0 0
  10. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  11. How useful did you find the suggested readings?
  12. 0 0 0 0
  13. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  14. Do you think a sufficient number of quizzes/exams were given?
  15. 0 0 0 0
  16. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  17. How helpful were the quizzes/exams?
  18. 0 0 0 0
  19. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  20. How fair were the exams (that counted towards your grade) testing your knowledge of the course material?
  21. 0 0 0 0
  22. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  23. Was classroom participation encouraged?
  24. 0 0 0 0
  25. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  26. Contents of the course
  27. 0 0 0 0
  28. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  29. How far was your understanding of the subject increased after taking this course?
  30. 0 0 0 0
  31. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  32. Impacts of the course
  33. 0 0 0 0
  34. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  35. Does it prepare you for research in that field?
  36. 0 0 0 0
  37. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  38. Should the same course be given to others (Assume you are again in the same batch).
  39. 0 0 0 0
  40. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  41. Knowledge of the instructor related to the course
  42. 0 0 0 0
  43. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  44. Preparation of the instructor
  45. 0 0 0 0
  46. Question: OPTION-A OPTION-B OPTION-C OPTION-D
  47. Preparation of the instructor
  48. 0 0 0 0
Any suggestion is highly appreciated.
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
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008
Jul 25th, 2008
-1

Re: error while retroeving data from mqsql database

Click to Expand / Collapse  Quote originally posted by masijade ...
Also, you definately should not be doing this stuff as scriptlets in a JSP. This is a maintenance nightmare.
No point to repeat that, this guy completely ignore that for last two weeks from me. Another hopeless case to bang on...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Jul 25th, 2008
0

Re: error while retroeving data from mqsql database

Click to Expand / Collapse  Quote originally posted by peter_budo ...
No point to repeat that, this guy completely ignore that for last two weeks from me. Another hopeless case to bang on...
Yeah, I've pretty much scaled back on saying this (nobody listens, they all want the "easy way out", then cry when they need to fix or modify it), but, sometimes, I'll climb back onto that horse for a round or two. ;-)
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jul 25th, 2008
-1

Re: error while retroeving data from mqsql database

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
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Jul 26th, 2008
0

Re: error while retroeving data from mqsql database

> 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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Jul 26th, 2008
0

Re: error while retroeving data from mqsql database

Click to Expand / Collapse  Quote originally posted by peter_budo ...
No point to repeat that, this guy completely ignore that for last two weeks from me. Another hopeless case to bang on...

yep ..... you have one witness here, who saw it first hand !!!
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Jul 28th, 2008
0

Re: error while retroeving data from mqsql database

Solved.
Thanks and Regards
Haresh
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008
Jul 28th, 2008
0

solved

Thanks and Regards
Haresh
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: can any one send me a jsp source code of an e-banking project
Next Thread in JSP Forum Timeline: Learning JSP- Bad tutorial.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC