SIGN UP MEMBER LOGIN:    
ARTICLE

Select a Specific Data From a Database in JSP

Posted by Vikas Mishra Articles | JSP January 11, 2012
This is the next article in the series of database applications in JSP. In this article, I am going to describe how to select specific data from a database.
Reader Level:
Download Files:
 

This is the next article in the series of database applications in JSP. In this article, I am going to describe how to select specific data from a database. First we construct a database and a DSN then generate a JSP application which selects specific data from a database. For constructing the database and DSN you may follow the first application of database ( working with database application in JSP). For developing this application we follow the following steps.

Step 1 : Create a New Project.

In this step we select New Project option from file menu.

create new project.jpg

Step 2 : Choose Project.

In this step we select web application from java web option and then click on the next button.

select new web application.jpg

Step 3 : Name and Location.

In this step we given it a specific name and set a specific location and click on the next button.

name and location.jpg

Step 4 : Server and Setting.

We select a specific server for this application and click on the next button.

server and setting.jpg

Step 5 : Select Framework.

There is no need to select any framework; for this application just click on the finish button.

selectframework.jpg

Step 6 : Create jsp file.

We create one jsp file for this application.

create new jsp file.jpg

selectdata.jsp

<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>
<HTML>
       <HEAD>
       <TITLE>
Select Data From a Database</TITLE>
       </HEAD>
       <BODY BGCOLOR="cyan">
            <H1>Select Data From a Database</H1>
            <%
                Connection connection = DriverManager.getConnection(
                "jdbc:odbc:data2");
                Statement statement = connection.createStatement() ;
                ResultSet resultset =
                statement.executeQuery("select * from table1 where City = 'Meerut'") ;
            %>
                <TABLE BORDER="1">
           <TR>
                 <TH>ID</TH>
                 <TH>Name</TH>
                 <TH>City</TH>
                 <TH>State</TH>
                 <TH>Country</TH>
          </TR>
           <% while(resultset.next()){ %>
           <TR>
                <TD> <%= resultset.getString(1) %></td>
               <TD> <%= resultset.getString(2) %></TD>
               <TD> <%= resultset.getString(3) %></TD>
               <TD> <%= resultset.getString(4) %></TD>
               <TD> <%= resultset.getString(5) %></TD>
          </TR>
           <% } %>
               </TABLE>
         </BODY>
</HTML>


Step 7 :
Compile and Run the application.

Now we compile the application and then run it on the server and find the following output.

Output

selectdata.jsp

index.jsp.jpg

Resources related to this article

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor