Home Answers Viewqa JSP-Servlet Problem displaying resultset in jsp(no frameworks used)

 
 


manjith
Problem displaying resultset in jsp(no frameworks used)
1 Answer(s)      3 years and 11 months ago
Posted in : JSP-Servlet

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









Related Pages:
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
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 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
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 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 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
JTable populate with resultset.
JTable populate with resultset.  How to diplay data of resultset... is helpful in displaying data in tabular format. You can also edit data. JTable...) JTable(Vector data, Vector columneNames) Here is a JTable populate with resultset
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
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
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 - 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
displaying List of records from database in a jsp using ajax
displaying List of records from database in a jsp using ajax  Sir, I...;%@page import="com.tbss.RtChannels"%><%@ taglib uri="http://java.sun.com/jsp...; In between the <div></div> I have to display the records. I am displaying
pagination problem - JSP-Servlet
a html file i wrote one form to call this servlet. In this servlet i used doget...(),my problem is that where i have to put & how to do pagination? my code...()"); } Connection connection = null; Statement statement = null; ResultSet
pagination problem - JSP-Servlet
a html file i wrote one form to call this servlet. In this servlet i used doget...(),my problem is that where i have to put & how to do pagination? my code...; ResultSet resultSet = null; @Override public void doGet(HttpServletRequest
arraylist problem - JSP-Servlet
arraylist problem  in my following code i have used a condition..."); ResultSet rs1=st1.executeQuery(sql1); ArrayList dstName=new ArrayList..."); ResultSet rs2=st1.executeQuery(sql2); ArrayList rscounter2=new
Displaying error on the Same form
Displaying error on the Same form  I want to display the errors on the same form(Top of the form) after validation. I am used Div element and Table.... But the problem is still. Could you please provide me the reason or possible
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
Connecting to MySQL database and retrieving and displaying data in JSP page
Connecting to MySQL database and retrieving and displaying data in JSP page... to the database getConnection() function of the DriverManager class is used. con...: select * from jakartaproject  Here is the code of our JSP
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
Closing Statement and ResultSet Objects - Development process
Closing Statement and ResultSet Objects  I Friend. i am getting the closing the objects problem. i am using the business logic in jsp now.it is having the two or more statements objects and results set objects ,how
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
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
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
displaying data
displaying data   how to display data from database on jsp using struts2
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 Constant values from Interface in JSP - JSP-Servlet
Displaying Constant values from Interface in JSP  Hi, ******Sorry... need to display suitable fields in my jsp but this should be done upon suitable...="COMP100"; // and so on } IN HOME JSP ****** home.jsp **** Currently
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
Struts Frameworks
Struts Frameworks Struts framework is very useful in the development of web.... These MVC design pattern in mostly used in the swing based application... of the leading framework being used all over the world by developers to create
ResultSet
ResultSet   What is a ResultSet
displaying section in the jsp based on the sected value in drop down - Java Beginners
displaying section in the jsp based on the sected value in drop down   Hi friend, i have one problem in my jsp. i.e i have to display section on the jsp based on the selected value in the drop down list using java script code
ResultSet
ResultSet  What is a ResultSet
Displaying the values in text fields of a form from a javascript function in jsp
Displaying the values in text fields of a form from a javascript function in jsp  Hi all, I have a requirement like this, First i have... is appreciated. Please help me in resolving this problem. Thanks & Regards
Resultset with one to many relationship
Resultset with one to many relationship   Suppose there are 5 tables... populate my bean classes from resultset without using hibernate, so... solution to this problem
Struts2...problem in JSP..unable to get the values for menuTitle!!!
Struts2...problem in JSP..unable to get the values for menuTitle!!!  ......n m fairly new in this framework.. there is some problem in this project...my Jsp is displaying the menuId from database but not the menuTitle...where as its
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
Session Problem in JSP - JSP-Servlet
Session Problem in JSP  I have developed a online feedback form in JSP platform. I have created normal session in JSP page. It is running in my... then the session is not working. I have not used EJB. Please tell me how can I track session
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
logout problem?? - JSP-Servlet
logout problem??  sir, the logout code which u have send... cache regarding that session object which used in particular application.this doesnt.../Logout.shtml http://www.roseindia.net/jsp/loginstatus.shtml Thanks
logout problem.. - JSP-Servlet
done in the code i have used session object in project's servlet and jsp...logout problem..  hi... first of all thanks for ur... but their is some problem with the the logout,i m not able to logout when
arraylist problem - JSP-Servlet
my code once again only in which i m facing the problem. /* * To change...(); System.out.println("helloooooooooooo"); ResultSet rs1...); ResultSet rs2=st1.executeQuery(sql2); ArrayList
codes for displaying in calendar
codes for displaying in calendar  can i get jsp codes for displaying comments, when the pointer is placed over the particular date in calendar
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
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
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
jfreechart displaying chart from access database
jfreechart displaying chart from access database  I have these 2...); ResultSet rs=ps.executeQuery(); out.println("hello1"); while... and then the chart should be displayed on a jsp..how can i do it..pls reply..its
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.