Fetching Data From A Database

 
 
This JSP source code is about fetching data from a database ....
 
 
  1. <%@ page import="java.sql.*" %>

  2. <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>

  3.  

  4. <HTML>

  5.     <HEAD>

  6.         <TITLE>Fetching Data From a Database</TITLE>

  7.     </HEAD>

  8.  

  9.     <BODY>

  10.         <H1>Database Lookup</H1>

  11.         <FORM ACTION="self.jsp" METHOD="POST">

  12.             Please enter the ID of the publisher you want to find:

  13.             <BR>

  14.             <INPUT TYPE="TEXT" NAME="id">

  15.             <BR>

  16.             <INPUT TYPE="SUBMIT" value="Submit">

  17.         </FORM>

  18.  

  19.  

  20.         <H1>Fetching Data From a Database</H1>

  21.  

  22.         <%

  23.             Connection connection = DriverManager.getConnection(

  24.                 "jdbc:odbc:data","userName","password");

  25.  

  26.             Statement statement = connection.createStatement();

  27.  

  28.             String id = request.getParameter("id")

  29.  

  30.             ResultSet resultset =

  31.                 statement.executeQuery("select * from tableName where id = '"   id   "'") ;

  32.  

  33.             if(!resultset.next()) {

  34.                 out.println("Sorry,could not find that publisher. " 

  35.                 "Please <A HREF='tryAgain.html'>try again</A>.");

  36.             } else {

  37.         %>

  38.  

  39.         <TABLE BORDER="1">

  40.             <TR>

  41.                <TH>ID</TH>

  42.                <TH>Name</TH>

  43.                <TH>City</TH>

  44.                <TH>State</TH>

  45.                <TH>Country</TH>

  46.            </TR>

  47.            <TR>

  48.                <TD> <%= resultset.getString(1) %> </TD>

  49.                <TD> <%= resultset.getString(2) %> </TD>

  50.                <TD> <%= resultset.getString(3) %> </TD>

  51.                <TD> <%= resultset.getString(4) %> </TD>

  52.                <TD> <%= resultset.getString(5) %> </TD>

  53.            </TR>

  54.        </TABLE>

  55.        <BR>

  56.        <%

  57.            }

  58.        %>

  59.     </BODY>

  60. </HTML>
 
Copy to Clipboard      Download code as Text Format
 
  Date entered : 23rd Jan 2007
  Rating : No Rating
  Accessed  :  2116
  Submitted by :  javabill
 
   Add Comment  Printer friendly
   View All Comments  Email to a friend
   Add to my Favourites Download PDF version
   Rating  
 
                 Click each image to add
this page to each site.
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
Related JSP Source Codes
Database error: Invalid SQL: select FLOOR( AVG(b.rating)) as avg_rating,a.sourcecode_id sourcecode_id ,title,description,author,category_id,skill_level,reference,reference_mail,reference_url,a.user_id user_id,date_entered,source,accessed,dev_id,file_url,total_comments,instruction,registered,authorised,fld_deletemark,fld_code_version,fld_searchkeyword,fld_code_status,category_id from tbl_sourcecode a LEFT JOIN tbl_sourcecodecomment b ON a.sourcecode_id = b.sourcecode_id LEFT JOIN tbl_codecategory c ON a.category_id = c.fld_categoryID where a.fld_deletemark = 'N' AND a.fld_enable_disable= 'Y' AND a.authorised='Y' AND c.fld_groupIDFK='4' AND a.sourcecode_id!='804' GROUP BY a.sourcecode_id order by a.sourcecode_id DESC limit 0, 5
MySQL Error: 1030 (Got error 122 from storage engine)
Session halted.
Warning: Unknown(): write failed: Disk quota exceeded (122) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0