Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  

Displaying Rows



Share on Google+Share on Google+

Emmanuel Aigbovbiosa
Displaying Rows
2 Answer(s)      9 years ago
Posted in : JSP-Servlet
View Answers

April 28, 2008 at 6:56 PM

Hi friend,

This is form code,


<title>display data in servlet</title>
<table border="1" width="50%" cellspacing="0" cellpadding="0">

<td width="100%">
<h2 align="center"> Display Data In Servlet</h2>
<form method="GET" action="DisplaydataAction">

<table border="1" width="100%" cellspacing="0" cellpadding="0">
<td width="30%"><b>Name:</b></td>
<td width="70%"><input type="text" name="name" size="20"></td>
<td width="30%"><b>Position :</b></td>
<td width="70%"><input type="text" name="position" size="20"></td>
<td width="30%"><b>Description:</b></td>
<td width="70%"><textarea rows="7" name="description" cols="30"></textarea></td>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="B2"></p>



import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DisplaydataAction extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws
ServletException, IOException{
PrintWriter out = response.getWriter();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
con = DriverManager.getConnection(url+db,"root","root");
Statement st = con.createStatement();
String firstname=request.getParameter("name");
String address=request.getParameter("position");
String description=request.getParameter("description");
int val = st.executeUpdate("insert dispalyInfo values(id,'"+firstname+"','"+address+"','"+description+"')");
out.println("Successfully insert data in database");
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
catch (Exception e){





read for more information,

April 28, 2008 at 6:59 PM

Display code,

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class RetriveDataAction extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
Statement stmt = null;
ResultSet rs = null;
PrintWriter out = res.getWriter();
try {
con = DriverManager.getConnection(url+db,"root","root");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT name, position,discription FROM dispalyinfo");
out.println("<html><head><title>Display Data from Database</title></head>");
out.println("<table border=1");
out.println("<html><head><title>" +
"<body bgcolor=\"#FFFFFF\">\n" +
"<table border=1 align=center>\n" +
"<TR bgcolor=\"#8AEAF4\">\n" +
while( {
out.println("<h2>Display Data From Database</h2>");
out.println("<td>" + rs.getString("name"));
out.println("<td>" + rs.getString("position"));
out.println("<td>" + rs.getString("discription"));
catch(ClassNotFoundException e) {
out.println("Couldn't found database driver: " + e.getMessage());
catch(SQLException e){
out.println("SQLException caught: " + e.getMessage());
finally {
try {
if (con != null) con.close();
catch (SQLException sql) {



Related Tutorials/Questions & Answers:
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 servlet or jsp  Hi friend, This is form code, display data
displaying data
displaying data   how to display data from database on jsp using struts2
Image is not displaying
Image is not displaying  Hii i am using spring javamail with html template to send mail,i am facing that image displaying prob when mail have to cm in gmail,in template just i am giving my current location of image which
displaying image
displaying image  how to upload image and retrieve it form database mysql in php?   Here is an example of uploading image using php. 1)form.html: <form method="post" enctype="multipart/form-data" action="upload.php
Comparison of corresponding rows in a DB
Comparison of corresponding rows in a DB  How to compare corressponding rows in a database using Java????? ex...!!! Thankin u
PHP Displaying URL Content
PHP Displaying URL Content  In my PHP application form, on submitting the form details it always displaying url content. Can anyone tell me what is the reason and how to restrict it from displaying
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
Count Rows - JSP-Servlet
Count Rows  How to count rows in Java. Thanks
Grid rows delete issue
Grid rows delete issue  I have a grid having rows with Remove button to remove rows,But we also havae an facility to remove those rows on onchange event of dropdown also,so if we delete middle row and then remove all rows
Displaying images - JDBC
Displaying images  How to display multiple images on a single jsp from MySql database
Displaying images - JDBC
Displaying images  How to display multiple images on a single jsp from MySql database
image displaying in java
image displaying in java  how to display an image by using load image button in applet viewer
(Displaying a calendar in GUI
(Displaying a calendar in GUI  (Displaying a calendar) Write a program that displays the calendar for the current month, as Use labels, and set texts on the labels to display the calendar."The Calendar and GregorianCalendar
autocomplete displaying multiple fields
autocomplete displaying multiple fields  How can I create an autocomplete with three field (name, id, phone). Placing the phone field in the appropriate input field but selecting the name field into the 'calling' input box
How to sort the rows in SQL?
How to sort the rows in SQL?  How to sort the rows in SQL?   Hi, Here is the answer, The ORDER BY clause allows you to sort the records in your result set. The ORDER BY clause can only be used in SELECT statements
xml displaying a drives data.....
xml displaying a drives data.....  Hi all, I need a solution for displaying content of a drive(Ex: c , d , e ) in the browser using the XML... a solution for displaying content of a drive(Ex: c , d , e ) in the browser using
How to insert rows in jTable?
How to insert rows in jTable?  Hi, I need to take input from user using JTable. I want an empty row to appear after clicking a insert button. The values will be entered in this empty row. I have searched on this but could
Displaying date in the preciding code
Displaying date in the preciding code  while deploying the Bill date field on this page are empty though it should be displayed String userName = request.getParmeter("userName"); String custId = request.getParameter("customerId
Dyanmically Adding Rows
Dyanmically Adding Rows  Hi sir Am doing project in that i need to add date picker in dynamically adding rows but the dates are storing in first test... rows in HTML table </TITLE> <link rel="stylesheet" type="text/css
displaying in ajax - Ajax
displaying in ajax  hi.. I have an Ajax page ,request gone to server ana details are bought... the response should be displayed in the same request page not in the other page... Thank u.. I will be waiting
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 file from database
Displaying file from database  I have list of files in my database. I want to display these files in browser according to the input. My need is like google search result. when i click on the link it should display
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 to display the error messages. It is working properly. But those error messages
Displaying files on selection of date.
Displaying files on selection of date.  Hi, I am developing a GUI, where i select from and to date. On selection of from and to date the GUI should show the particular txt files of the selected date. I want the java logic
Dyanmically Adding Rows with Date Picker
Dyanmically Adding Rows with Date Picker  Hi Sir, I am doing a project in that i need to add rows dynamically with date picker inside row, send me code as soon as possible. Regards, Santhosh
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
Php Sql num rows
Php Sql num rows This example illustrates how to find number of rows... and find the number of rows of the table by mysql_num_rows methods. The output...);   $num_rows = mysql_num_rows($result);   
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
MySQL Affected Rows
MySQL Affected Rows This example illustrates how to show the affected rows... rows affected (0.08 sec)   Here update a table "...; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0
JavaScript Hide Table Rows
JavaScript Hide Table Rows...; In this section, you will learn how to hide table rows using JavaScript... object grabs the id of the table. Then we have determined the length of rows
Php Sql Number of Rows
Php Sql Number of Rows  This example illustrates how to count the rows... of rows of the table. To find the number of the rows we use the mysql_num_rows..._rows($res);     print("$number_of_rows rows