Results 1 to 6 of 6
  1. #1
    zamani is offline Member
    Join Date
    Apr 2014
    Posts
    1
    Rep Power
    0

    Exclamation i want to retrieve data from a database in mysql and display the data in an html tabl

    help urgently needed, i have been battling with this problem for days and still haven't found any solution yet. i want to retrieve datas from a table in mysql and display it as a table in html. i got a format online and i try to apply the same approach, but each time i run the code i get this errror messges

    type Exception report

    message An exception occurred processing JSP page /crimeinfo.jsp at line 32

    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 /crimeinfo.jsp at line 32

    29:
    30:
    31: <%List <String> data =(List)request.getAttribute("data");
    32: Iterator <String> itr = data.iterator() ;
    33: for (itr = data.iterator();
    34: itr.hasNext();)
    35: {%>


    i dont know what else to do because i have tried everything within my knowledge. i would really appreciate if any body here can help me. thanks...
    here are my codes.


    crimeinfo.jsp

    <%@ page language="java" import="java.sql.*" import="java.util.*" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!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=ISO-8859-1">
    <title>Crime Report</title>
    </head>
    <body>

    <table border="1" with="600">
    <tr><td><tb><td>SuspectName</td></b>
    <td><tb>SuspectAlias</b></td>
    <td><tb>suspectaliases</tb></td>
    <td><tb>Height</tb></td>
    <td><tb>suspectht</tb></td>
    <td><tb>Gender</tb></td>
    <td><tb>suspectgender</tb></td>
    <td><tb>Features</tb></td>
    <td><tb>features</tb></td>
    <td><tb>Address</tb></td>
    <td><tb>crimeaddress</tb></td>
    <td><tb>CrimeType</tb></td>
    <td><tb>crimetype</tb></td>
    <td><tb>CaseNumber</tb></td>
    <td><tb>caseno</tb></td>
    <td><tb>Status</tb></td>
    <td><tb>casestatus</tb></td></tr>

    <% Iterator <String> itr;%>
    <%List data =(List)request.getAttribute("datalist");
    for (itr = data.iterator();
    itr.hasNext();)
    {%>

    <tr>
    <%String s =(String)itr.next(); %>
    <td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td>
    <tr><td><%=itr.next()%>></td></tr>
    <%} %>
    </table>
    </body>
    </html>



    viewcrimereport.java

    package pack;
    import java.sql.*;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.*;

    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import com.lowagie.text.List;
    public class viewcrimereport extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    private ServletConfig config;
    //Setting Jsp page
    String page = "crimeinfo.jsp";
    public void init(ServletConfig config)
    throws ServletException{
    this.config = config;
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


    PrintWriter out=response.getWriter();
    response.setContentType("text/html");

    Connection conn = null;
    String url = "jdbc:mysql://localhost/citycrime";
    String userName = "root";
    String passw = "jids";
    PreparedStatement pst = null;
    ResultSet rs;
    ArrayList<String> datalist = new ArrayList<String>();

    try
    { int i=0;
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    conn = DriverManager.getConnection(url, userName, passw);
    pst = conn.prepareStatement("");

    String sql ="select suspectname,suspectaliases,suspectht,suspectgender ,features,crimeaddress,crimetype,caseno,casestatus from crimereport";
    pst.executeQuery(sql);
    rs = pst.getResultSet();
    while(rs.next()){
    datalist.add(rs.getString("suspectname"));
    datalist.add(rs.getString("suspectaliases"));
    datalist.add(rs.getString("suspectht"));
    datalist.add(rs.getString("suspectgender"));
    datalist.add(rs.getString("features"));
    datalist.add(rs.getString("crimeaddress"));
    datalist.add(rs.getString("crimetype"));
    datalist.add(rs.getString("caseno"));
    datalist.add(rs.getString("casestatus"));}
    rs.close();
    pst.close();
    }
    catch(Exception e){System.out.println("Exception is;"+e);}

    request.setAttribute("data",datalist);

    RequestDispatcher dispatcher = request.getRequestDispatcher(page);

    if (dispatcher != null){
    dispatcher.forward(request, response);
    }
    }
    }


    viewcrimereport.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!--web.xml code-->
    <servlet>
    <servlet-name>viewcrimereport</servlet-name>
    <servlet-class>viewcrimereport</servlet-class>
    <servlet-mapping>
    <servlet-name>viewcrimereport</servlet-name>
    <url-pattern>viewcrimereport</url-pattern>
    </servlet-mapping></servlet>

    thanks for your help

  2. #2
    Join Date
    Apr 2014
    Posts
    49
    Rep Power
    0

    Default Re: i want to retrieve data from a database in mysql and display the data in an html

    can you try with

    while (itr.hasNext()) {
    //more code
    }

    instead of

    for (itr = data.iterator();
    itr.hasNext();)

  3. #3
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    448
    Rep Power
    6

    Default Re: i want to retrieve data from a database in mysql and display the data in an html

    Hi,

    Please dont post this kind of message again here. I worried about only the length of message not the content. Please let us know only where you are strucking.

    Based on quick check of your code, I think the issue was due to Generics. As far as I know, some old version jsp does not support generics. Hopefully, it would work if you remove generics in JSP.
    Mak
    (Living @ Virtual World)

  4. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,982
    Rep Power
    5

    Default Re: i want to retrieve data from a database in mysql and display the data in an html

    Quote Originally Posted by makpandian View Post
    Hi,

    Please dont post this kind of message again here. I worried about only the length of message not the content. Please let us know only where you are strucking.
    Dude, the biggest problem we have here is that people refuse to provide enough information. And now you come along and tell people to post less!? Why don't you wait a bit passing off forum-ethics behavior suggestions until you have been around a little longer and know what others posting in this forum expect? This is not your personal playground you know.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: i want to retrieve data from a database in mysql and display the data in an html

    makpandian's been around for ages.
    Has the occasional posting attack and then fades away for a bit before re-emerging.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,982
    Rep Power
    5

    Default Re: i want to retrieve data from a database in mysql and display the data in an html

    I see. Well then the joke's on me.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. how to retrieve data using <select> tag from database
    By shyamgsk in forum Java Servlet
    Replies: 6
    Last Post: 09-20-2013, 04:10 PM
  2. Replies: 3
    Last Post: 09-08-2012, 03:38 AM
  3. How to display data against row clicked on html table?
    By reubenmk in forum Java Servlet
    Replies: 3
    Last Post: 02-23-2012, 02:20 PM
  4. Mysql data to build a HTML form
    By skigodmg in forum Java Servlet
    Replies: 1
    Last Post: 03-22-2011, 05:29 AM
  5. Displaying data from mysql database.
    By Haresh gurav in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-09-2008, 02:54 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •