Displaying Rows

Displaying Rows

View Answers

April 28, 2008 at 6:56 PM

Hi friend,

This is form code,

<html>
<head>

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

<tr>
<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">
<tr>
<td width="30%"><b>Name:</b></td>
<td width="70%"><input type="text" name="name" size="20"></td>
</tr>
<tr>
<td width="30%"><b>Position :</b></td>
<td width="70%"><input type="text" name="position" size="20"></td>
</tr>
<tr>
<td width="30%"><b>Description:</b></td>
<td width="70%"><textarea rows="7" name="description" cols="30"></textarea></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="B2"></p>
</form>
</td>
</tr>
</table>

</body>

</html>

-----------------------------
import java.io.*;
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{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
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+"')");
con.close();
out.println("Successfully insert data in database");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

}
}

----------------------------------

<servlet>
<servlet-name>displaydata</servlet-name>
<servlet-class>DisplaydataAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>displaydata</servlet-name>
<url-pattern>/DisplaydataAction</url-pattern>
</servlet-mapping>

----------------------------------------

read for more information,

http://www.roseindia.net/servlets/


April 28, 2008 at 6:59 PM

Display code,

import java.io.*;
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;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try {
Class.forName("com.mysql.jdbc.Driver");
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("<body>");
out.println("<table border=1");
out.println("<tr>");
out.println("<td>");
out.println("<html><head><title>" +
"<body bgcolor=\"#FFFFFF\">\n" +
"<table border=1 align=center>\n" +
"<TR bgcolor=\"#8AEAF4\">\n" +
"<td>Name</td><td>Position</td><td>Discription</td>\n");
out.println("<tr>");
while(rs.next()) {
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"));
}
out.println("</td></tr>");
out.println("");
out.println("</table>");
out.println("</td>");
out.println("</tr>");
out.println("</table>");
out.println("</body></html>");
}
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) {
System.out.println(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
Advertisements
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
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
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
ModuleNotFoundError: No module named 'rows'
ModuleNotFoundError: No module named 'rows'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'rows' How to remove the ModuleNotFoundError: No module named 'rows' error
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
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... all, I need a solution for displaying content of a drive(Ex: c , d , e
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,ADS_TO_REPLACE_1 The ORDER BY clause allows you to sort the records in your result set. The ORDER BY clause can only be used
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
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 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
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
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
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 Error pages in results tree in jmeter
Displaying Error pages in results tree in jmeter   Displaying Error pages in results tree in jmeter
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..._rows($result);   echo "<b>$num_rows Rows 
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
MySQL Affected Rows
MySQL Affected Rows This example illustrates how to show the affected rows...; Query OK, 0 rows affected (0.08 sec)   Here update a table...   Query OK, 0 rows affected (0.00 sec) Rows matched: 1
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..._of_rows = mysql_num_rows($res);     print("
return all rows mysql php
return all rows mysql php  How to find or return results that are not available in another table .. using join method in PHP and MYSql.   SELECT * FROM Declined LEFT JOIN Request ON Declined.RequestID
Displaying database values in pdf format
Displaying database values in pdf format  Hi All, I am developing a struts application.I am having one registration form when i am submitting the form the values are stored in database,the database name is registration
displaying a physical webpage with frames in iframe
displaying a physical webpage with frames in iframe  i have iframe in my webpage, i have done the coding part for browsing the folders and viewing...="sss"><%=s%></a> <% } %> mycode for displaying
SQL select statement doesn't return any rows,
SQL select statement doesn't return any rows,  When an SQL select statement doesn't return any rows, is an SQLException thrown
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. The result should be display below my title. How do i solve it? Thank you so
reading and displaying svg file through java
reading and displaying svg file through java  sample program for reading a svg file
Displaying calendars - Java Interview Questions
Displaying calendars  Write a program that prompts the user to enter the year and first day of the year, and displays the calendar table for the year on the console. For example, if the user entered the year 2005, and 6
MySQL Affected Rows
MySQL Affected Rows       When we execute Sql query, it may affect some rows of the table... the successful message with the number of rows affected by the query
displaying image in awt - Java Beginners
displaying image in awt  Hi All, I have downloaded the code to display image using awt from here and when I execute the code I am getting error like: D:\netbeans\myjavaappl\src\ImageDemo.java:21: incompatible types
HOW TO DISPLAY 2 ROWS OF CONTROLS
HOW TO DISPLAY 2 ROWS OF CONTROLS  i can be display one row by selecting value from drop down box BUT ALSO i need to display 2 rows by selecting value from drop down box of textbox's and radio button,drop down box using
Write a query to find the total number of rows in a table
Write a query to find the total number of rows in a table  Write a query to find the total number of rows in a table?   Hi, Here is the answer,ADS_TO_REPLACE_1 we can find the total number of rows in a table using
Shading Rows in JTable
Shading Rows in JTable     ... the shading rows in JTable. But, the question arises what is shading?.  Shading Rows: In JTable component the shading rows are the simplest way of shading
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
Adding checkbox in table using that delete table rows
that checkbox select more than than one rows,and using delete button i want to delete the selected rows using swing in java
how to search the string arraylist contains database rows?
how to search the string arraylist contains database rows?  i need to search 2 database. one is excel database and another is SQL database. stored the row values into string arraylist. now i want to print the common rows existed
Php Sql num rows
Php Sql num rows       This tutorial illustrates how to find number of rows of the table... to find the number of rows in the table. We created a connection from database

Ads