Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training Big Data and Hadoop Training Java Training  
 

Problem displaying resultset in jsp(no frameworks used)

Ads

 
 

Share on Google+Share on Google+

manjith
Problem displaying resultset in jsp(no frameworks used)
1 Answer(s)      8 years ago
Posted in : JSP-Servlet
Ads
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:
Problem displaying resultset in jsp(no frameworks used) - JSP-Servlet
Problem displaying resultset in jsp(no frameworks used)  Problem... if the resultset return 25 rows, these 25 records are to be displayed in my jsp. My problem... resultset values to a bean 2)the respective bean instances are added
resultset problem - JSP-Servlet
resultset problem  hi I have one problem with resultset? ResultSet rs=st.execute("select subjname,staffname from staffdetails"); while... is java.sql.SQLException: Operation not allowed after ResultSet closed how
Advertisements
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
displaying images and records problem - JSP-Servlet
displaying images and records problem  hi, Thanks for your reply to my question. The code you sent to me last week is not working. it doesn't.... Please, kindly help me to solve the problem urgently. Or in any other way to do
displaying employee records and their images problem - JSP-Servlet
displaying employee records and their images problem  hi, Thanks for your reply to my question. The code you sent to me yesterday was not working. it doesn't display any record and image. Please, help me out urgent
displaying both image and records problem in jsp and servlet - JSP-Servlet
displaying both image and records problem in jsp and servlet  hello, Thanks for your reply on the question i asked the other time. It worked... friend, Code to help solve the problem. Download Images
JSP - Resultset - JSP-Servlet
JSP - Resultset  hello sir, how can i count record in jsp. i use resultset in my jsp so in my login form how can i check the username... code Count data from database in jsp Count data from
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
Displaying Date in jsp - JDBC
Displaying Date in jsp  I want to insert Date of birth of a person in a database.i am getting input value from HTML and i use jsp application to interact with database.My JSP code for inserting Date is below: String dateStr
Displaying Rows - JSP-Servlet
Displaying Rows  Hi, I need your support on how to display data from ms sql 2000 database into an html form text box and text area, using java...:3306/"; String db = "register"; Statement stmt = null; ResultSet rs
Getting ResultSet size - JSP-Servlet
Getting ResultSet size  Hello friends, what is the result getFetchSize() of resultset. I got error with this method. While rs contains... the driver. It has absolutely no effect on the number of rows in a ResultSet. The driver
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
ResultSet
ResultSet   What is a ResultSet
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
ResultSet
ResultSet  What is a ResultSet
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
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
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
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
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
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
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
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
JSP Problem - JSP-Servlet
JSP Problem  Hi, I have problem,this is my senario I have one jsp,this jsp having the 3 fields.let me take 3fields userName,emailAddress... for more information, http://www.roseindia.net/jsp Thanks
jsp problem - JSP-Servlet
jsp problem  here is a code for Retrieving image from mysql database through jsp. but i cann't set size of image when it was display so what should... working but my problem is size of image. so can u just help?? code
jsp problem - JSP-Servlet
jsp problem  here is a code for Retrieving image from mysql database through jsp. but i cann't set size of image when it was display so what should... working but my problem is size of image. so can u just help?? code
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