Problem displaying resultset in jsp(no frameworks used)

Ads
 

Problem displaying resultset in jsp(no frameworks used)

View Answers

July 9, 2009 at 4:59 PM

Hi friend,

Try the following code:

1)dataBean.jsp:
<%@ page language="java" import="java.sql.*, java.io.*, java.util.*" %>
<jsp:useBean id="test" class="form.Retrievedata" />

<html>
<head><title> test database </title></head>

<body>
<table width="50%" border="1">
<tr><th>Roll No</th><th>Name</th><th>Marks</th><th>Grade</th></tr>
<%
test.connect ();

Iterator itr;
List data= test.viewDatabase ();
for (itr=data.iterator(); itr.hasNext(); ){

%>
<tr>
<td><%=itr.next()%></td>
<td><%=itr.next()%></td>
<td><%=itr.next()%></td>
<td><%=itr.next()%></td> </tr>
<%
}

test.disconnect ();
%>
</table>
</body>
</html>

2) Retrievedata.java

package form;

import java.sql.*;
import java.util.*;

public class Retrievedata
{
List dataList = new ArrayList();
Connection con;

public void connect() throws Exception{
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
}
catch (ClassNotFoundException e) {
System.out.println(e);
}
}

public void disconnect() throws SQLException {
try {
if ( con != null ) {
con.close();
}
}
catch (SQLException ex) {
System.out.println(ex);
}
}

public List viewDatabase () throws SQLException, Exception {
ResultSet rs = null;
try {
String queryString = "Select * From student;";
Statement stmt = con.createStatement();
rs = stmt.executeQuery(queryString);
while (rs.next ()){
dataList.add(rs.getInt("rollNo"));
dataList.add(rs.getString("name"));
dataList.add(rs.getInt("marks"));
dataList.add(rs.getString("grade"));
}
}
catch (Exception e) { }
return dataList;
}
}
For more information, please visit the following link:
http://www.roseindia.net/jsp/servlet-jsp-data-list.shtml

Thanks

Ads









Related Tutorials/Questions & Answers:
JSP - Problem of displaying result at webpage
JSP - Problem of displaying result at webpage  Can anyone please help to solve my problem below. My webpage has problem in displaying result position... stmt = connection.createStatement(); ResultSet rs
Resultset - JSP-Servlet
Resultset  I am writing while(rs.next){} but if resultset is null then it cannot enter in while block. I want,if resultset is null then it will enter into the while block.  Hi friend, A ResultSet object
Advertisements
Displaying image using jsp and spring.
Displaying image using jsp and spring.  how to display an image stored in WEB-INF/images folder on the browser using jsp and spring
jsp problem
jsp problem  problem:::::::: On JSP form ,when i insert data in text field........at that time action is perform and data is retriev from data base..."); Statement st=con.createStatement(); ResultSet rs=st.executeQuery
displaying long size arrow line in a jsp
displaying long size arrow line in a jsp  Hi all, How can we display an arrow mark with a specified height and width in a jsp. Please help me in resolving this problem. Thanks, Suresh
jsp problem
jsp problem  Hi every one plz give me answer for below question ASAP I created one JSP(used pre defined javascript in jsp to get rtf format in browser) which creats RTF Format in browser to enter data. MY question is after i
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Jsp problem
Jsp problem  Hello friends.I want to share my jsp problem.I want to show all of my database(mysql) tables except two(user,manufacturer) in a jsp page.plssss help me
jsp problem
jsp problem  Hello Friends, I want to show one page for 5 seconds and after that i want to redirect the page to another URL
Uploading a software and displaying it on the jsp page
Uploading a software and displaying it on the jsp page  I have a Downloads page in my website, I want it to display the name of softwares as soon as it is uploaded in the backend by the administrator. And the admin may be a non
Retrieving newly inserted records and displaying in jsp forever
Retrieving newly inserted records and displaying in jsp forever  Sir... a table and display in jsp(Each row contains a field called as "session... of every record which is displayed on the jsp (not in database) and immediately i have
Data displaying with limited records in jsp
Data displaying with limited records in jsp  How to display table with limited 10 records , after clicking next button another 10 records from database upto last record please help me
displaying data retrieved from a database in a jsp page
displaying data retrieved from a database in a jsp page  the page should display username, emailid, telephone in addition to tthe tagline however...(sql); stmt.setString(1, custId); ResultSet rs = stmt.executeQuery(); if (rs.next
forwarding request to a jsp from a filter and displaying image in that jsp
forwarding request to a jsp from a filter and displaying image in that jsp ... correctly, but in login.jsp the image is not displaying. Can you help me in resolving this problem. Thanks & Regards, Suresh   Jsp Display Image <
Displaying java.util.Calendar using JSP struts tags
Displaying java.util.Calendar using JSP struts tags  My question is in regard to displaying a date whose source is java.util.Calendar and not java.util.Date. In all the examples I have found they only refer to the java.util.Date
jsp reload current page problem
jsp reload current page problem  Hi, i am facing problem while reloading the JSP page
jsp reload current page problem
jsp reload current page problem  Hi, i am facing problem while reloading the JSP page
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want..."')"); ResultSet rs = stmt.executeQuery( "SELECT * FROM data"); String id.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want..."')"); ResultSet rs = stmt.executeQuery( "SELECT * FROM data"); String id.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want..."')"); ResultSet rs = stmt.executeQuery( "SELECT * FROM data"); String id.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
Radio Button Problem in jsp.
Radio Button Problem in jsp.  I have a small doubt in my application...=connection.createStatement(); ResultSet rs=st.executeQuery("Select * from test...:3306/register","root";, "root"); Statement stmt=connection.createStatement(); ResultSet rs
JSP code problem - JSP-Servlet
JSP code problem  HI.. I have a DB2 stored procedure wich return a result set. I have made a report basing on this procedure using Crystal Reports. How to pass parameters to this procedure with java code in a JSP page
jsp and bean problem
jsp and bean problem  Hi i have the following jsp code... Can you plz...://200.0.0.153:3306/snms"; Connection connection = null; ResultSet rs=null; ResultSet rs1=null; Statement statement=null; // Load JBBC driver
ResultSet
ResultSet  I want to retrieve data of unknown datatype from database.how to do it using resultset or Resultsetmetadata.Can you please tell me what... = con.createStatement(); ResultSet rs = st.executeQuery
Statistical charts in JSP - problem
Statistical charts in JSP - problem  hey! i get this error when i run... org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred... An error occurred at line: 11 in the jsp file: /BarChart.jsp
JSP run problem
JSP run problem  type Exception report message description... this request. exception org.apache.jasper.JasperException: Exception in JSP...) root cause java.lang.NullPointerException org.apache.jsp.bb_jsp
problem in jsp using ms-access
problem in jsp using ms-access  after starting server(tomcat) wen v...)Your DSN will get created. 6) Restart your server and run your jsp code. Here...(); ResultSet rs=st.executeQuery("select * from data"); while(rs.next()){ %>
displaying a calendar of only current month in jsp on webpage using javascript
displaying a calendar of only current month in jsp on webpage using javascript  how can we display a calendar of only current month in jsp on webpage using javascript
problem in record viewing in jsp - JSP-Servlet
problem in record viewing in jsp  hai i send the code can you please find where is the problem it is not showing any error but i cannot able to view the record after eclipse ide is closed and reopen it i have used the jsp

Ads