Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Displaying Rows
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Emmanuel Aigbovbiosa
Displaying Rows
2 Answer(s)      6 years and 8 months ago
Posted in : JSP-Servlet



Advertisement
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
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
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
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
image displaying in java
image displaying in java  how to display an image by using load image button in applet viewer
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
(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
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
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 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
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
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 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
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 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 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
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 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
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
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);   
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
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
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
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 
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
Advertisements
 

 

 

DMCA.com