jsp database

jsp database

I want to retrive value in my jsp page but i dont want show my database query in my jsp page. is there any other method to show value in my jsp page using java class

View Answers

November 16, 2010 at 12:31 PM

Hi Friend,

Try the following code:

1)DataServlet.java:

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

public class DataServlet extends HttpServlet{
String page="/jsp/data.jsp";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
String connectionURL = "jdbc:mysql://localhost:3306/test";
Connection connection=null;
ResultSet rs;
response.setContentType("text/html");
List dataList=new ArrayList();
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "root");
String sql = "select * from data";
Statement s = connection.createStatement();
s.executeQuery (sql);
rs = s.getResultSet();
while (rs.next ()){
dataList.add(rs.getString("name"));
 dataList.add(rs.getString("address"));
}
rs.close ();
s.close ();
}
catch(Exception e){
System.out.println("Exception is ;"+e);
}
request.setAttribute("data",dataList);
RequestDispatcher dispatcher = request.getRequestDispatcher(page);
if (dispatcher != null){
dispatcher.forward(request, response);
}
}
}

2)data.jsp:

<%@page language="java" import="java.util.*" %>
<html>
<head>
<title>Data Page</title>
</head>
<body> 
<table border="1" width="303">
<tr>
<td ><b>Name</b></td>
<td><b>Address</b></td>
</tr>
<%Iterator itr;%>
<% List data= (List)request.getAttribute("data");
for (itr=data.iterator(); itr.hasNext(); )
{
%>
<tr>
<td ><%=itr.next()%></td>
<td ><%=itr.next()%></td>
</tr>
<%}%>
</table>
</body>
</html>

3)In web.xml, do the servlet mapping:

    <servlet>
        <servlet-name>DataServlet</servlet-name>
        <servlet-class>DataServlet</servlet-class>
    </servlet>
<servlet-mapping>
        <servlet-name>DataServlet</servlet-name>
        <url-pattern>/DataServlet</url-pattern>
    </servlet-mapping>

Thanks









Related Tutorials/Questions & Answers:
jsp database
jsp database   I want to retrive value in my jsp page but i dont want show my database query in my jsp page. is there any other method to show value in my jsp page using java class
connect to the database from JSP
connect to the database from JSP  How do you connect to the database from JSP?   A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets
Advertisements
connec to database - JSP-Servlet
connec to database  Need code to connect the application to database. I have developed the application JSP and Servlet
upload to database - JSP-Servlet
to upload a pdf file into database(sqlserver2000) using jsp. In roseindia some examples... into database whenever i want that uploaded pdf file i have to retrieve it from database please help me friends thanks in advance it is very urgent
JSP Database Example
This example shows you how to develop JSP that connects to the database and retrieves the data from database. The retrieved data is displayed on the browser. Read Example JSP Database Example Thanks
connection with database - JSP-Servlet
and the connection with the database using jsp code, I get exceptions that I have... with java code. Is there any other way to establish a connection with database in jsp... with the database by writing the program in java. Following is the code: import
line chart from database in jsp
line chart from database in jsp  how can i create line chart from database in jsp code
Jsp Code to store date in database - JSP-Servlet
Jsp Code to store date in database   Hi, Can u give me jsp code to store current date in to database. Thanks Prakash
How to access the database from JSP?
How to access the database from JSP?  Hi, What is the process of accessing the database from JSP page? Thanks   Hi, In the JSP program... database from JSP which explains you how to access the database by embedding
jsp with database oracle
jsp with database oracle  hai i am doing one program in jsp i want to check the jsp life cycle methods so wrote one program, in which i write jspInit() method and jspDestroy() methods. but i am getting error i crate a table
jsp with database.. - Development process
jsp with database..  Hello i need code for..... I have a car... of that brand should be retrieved from database.i have created a table in database... Thanks  For the above code, create database table named
JSP and Database access
JSP and Database access  Hi, Please help me with the following program. I am not able to update all the pa column values in my database. csea.jsp: <html> <body> <%@page import="java.sql.*"%> <form method
database through jsp
database through jsp  sir actually i want to retrieve the data from database dynamically.because i dont know how many records are there in the database? thanks   Here is an example of jsp which retrieves data from
Connecting to Database from a hyperlink in JSP - JSP-Servlet
Connecting to Database from a hyperlink in JSP  How can I connect to database by clicking on a hyperlink in a JSP Page.Can you please give me sample... which is connect to database using jdbc database
Backup MySQL Database - JSP-Servlet
Backup MySQL Database  Database Sir I have been reading Rose's india tutorial "Using MySQL Database with JSP/Servlet". In the Tutorial you have shown an example of backing up the database. When I tried to backup database
edit values of database using jsp
edit values of database using jsp  hi i want a code to edit the row from tye database and display in a page which containd radio buttons and drop down boxes using jsp code
edit values of database using jsp
edit values of database using jsp  hi i want a code to edit the row from tye database and display in a page which containd radio buttons and drop down boxes using jsp code
database - JSP-Servlet
database  how to downloaad a file(doc) from database and store in any local system by using servlet
To insert attachment file in database in JSP.
To insert attachment file in database in JSP.  I am doing project in JSP. How to insert attachment file in mysql database? Please suggest some solution. Your inputs is valuable to me.   Hi Friend, Visit HereADS
oracle database backup using jsp
oracle database backup using jsp   I want to take the backup of oracle database.I want to write the code in jsp ,so that when the page is loaded a backup of the database is stored in one of my local drives.Is it possible to do
jsp and database - Java Beginners
jsp and database  I m making a project for an agentto store record using jsp and oracle database.I want that when the premium of any policy holder is half yearly or quarterly then when the person submit premium in a month lets
Update Database from jsp
Update Database from jsp   I want to update my oracle database column from a text box ,so whenever I input some text value in the text box and click UPDATE button the database field should be updated . I have a drop down menu
display date to jsp from database
display date to jsp from database   display date to jsp from database to calender if the start date and end date is available than calender date... not available in database field than show in green color and clickable. NOTE :- Date
Draw graph using jsp without database connection
Draw graph using jsp without database connection  Draw graph using jsp code without database connection
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
Problem in Jsp and database - Development process
Problem in Jsp and database  Hi, How can I reterive values from database and display them in teextboxes so that when the user select the UPDATE... to the database itself . Thanks in advance.  Hi Friend, You can use
Database connectivity with jsp code - JSP-Servlet
Database connectivity with jsp code  I have written a program in java having connectivity with online_exam. Its working properly. Connection has been... is there with jsp code.Its giving the exceptions I have posted u before. I dont know
search functionality using jsp from database
search functionality using jsp from database  search functionality using jsp from database
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
jsp with excel sheet data uploading into database
jsp with excel sheet data uploading into database  how to upload data in excel sheet with jsp into oracle 10g database
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
data are not display in JSP from database - JSP-Servlet
data are not display in JSP from database   i want to finding some data through a SQL query from SQL server database to a JSP page based on some... of this jsp page. like.. School Result and three request parameters 'class', 'from
database connectivity using jsp code
database connectivity using jsp code  i have two tables employee...),'bbbb','bbbb'); so this syntax is possible to use in jsp code based on employee id ename and designation are displayed how it is possible in jsp employee
3 dropdown list from the database using JSP
3 dropdown list from the database using JSP  Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
common database jsp file for all the jsp files in the application
common database jsp file for all the jsp files in the application  hi... use of this single jsp file while connecting to database rather than writing connectivity code in all the jsp pages . send me the code for that . thanks
connecting to a database dynamically - JSP-Servlet
connecting to a database dynamically   abc.html... java.lang.NullPointerException org.apache.jsp.abc_jsp._jspService(abc_jsp.java:72... with database dynamically. Plz debug the code and explain the reasons for the exception
jsp- database dependent dropdown list
jsp- database dependent dropdown list   i want 2 dropdown list 1- CLASS 2-SECTION both are should come from database. and if i select a class... respective to that class from database. please help by providing the code in jsp
How to retrieve image from mysql database in JSP?
How to retrieve image from mysql database in JSP?  Hi, I need JSP... to retrieve image from mysql database in JSP? Thanks   Hi, You can write... images from Database in JSP. Thanks
Static database class - JSP-Servlet
Static database class  I want to create a static database class and i want to use that class in all servlets ? How can i achive
How to retrieve blob image from database in JSP?
How to retrieve blob image from database in JSP?  Hello, JSP is used... the blog image from database. How to retrieve blob image from database in JSP?   Hi, Please check the tutorial Retrieve image from database using
How to store and retrieve image from database in JSP?
How to store and retrieve image from database in JSP?  Hi, In one of my application I have to store and then display the image in JSP. How to store and retrieve image from database in JSP? Thanks   HI, You can use
jsp -sevlet connecting to database using dropdown
jsp -sevlet connecting to database using dropdown  How can I get my dropdown list from oracle database and then submit it to another table in JSP. I... to the database and fetches an array of strings from a database table and then sends
To insert attachment file in database in JSP.
To insert attachment file in database in JSP.  I am doing project in JSP. How to insert attachment file in mysql database? Please suggest some solution. Your inputs is valuable to me.   Hi Friend, Try the following
draw the running or moving graph using database in jsp
draw the running or moving graph using database in jsp  hi my question is how to draw the running or moving graph using jsp and take x and y co-ordinate value from database
draw the running or moving graph using database in jsp
draw the running or moving graph using database in jsp  hi my question is how to draw the running or moving graph using jsp and take x and y co-ordinate value from database
edit database using jsp and servlet
edit database using jsp and servlet  I am creating a website using jsp and servlets that is used to view houses from a database. I want to be able... information from the database in the textboxes. Please help me to display
server database connection - JSP-Servlet
server database connection  sir generally we will connect to the database by using the following steps 1.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver..." in that case how we will get the database connection   Hi Friend
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp

Ads