Java
  Home arrow Java arrow Page 3 - The JSP Files (part 5): No Forwarding ...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

The JSP Files (part 5): No Forwarding Address
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2001-03-19

    Table of Contents:
  • The JSP Files (part 5): No Forwarding Address
  • Dumped!
  • The Scenic Route
  • One Step At A Time
  • New Friends
  • No Forwarding Address
  • Cleaning Up

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The JSP Files (part 5): No Forwarding Address - The Scenic Route


    (Page 3 of 7 )

    All working? Good. Now, let's use JSP to do exactly the same thing - fire a SELECT query at the database, and display the results in an HTML page.

    <html> <head> <basefont face="Arial"> </head> <body> <%@ page language="java" import="java.sql.*" %> <%! // define variables String UId; String FName; String LName; // define database parameters String host="localhost"; String user="us867"; String pass="jsf84d"; String db="db876"; String conn; %> <table border="2" cellspacing="2" cellpadding="5"> <tr> <td><b>Owner</b></td> <td><b>First name</b></td> <td><b>Last name</b></td> </tr> <% Class.forName("org.gjt.mm.mysql.Driver"); // create connection string conn = "jdbc:mysql://" + host + "/" + db + "?user=" + user + "&password=" + pass; // pass database parameters to JDBC driver Connection Conn = DriverManager.getConnection(conn); // query statement Statement SQLStatement = Conn.createStatement(); // generate query String Query = "SELECT uid, fname, lname FROM abook"; // get result ResultSet SQLResult = SQLStatement.executeQuery(Query); while(SQLResult.next()) { UId = SQLResult.getString("uid"); FName = SQLResult.getString("fname"); LName = SQLResult.getString("lname"); out.println("<tr><td>" + UId + "</td><td>" + FName + "</td><td>" + LName + "</td></tr>"); } // close connection SQLResult.close(); SQLStatement.close(); Conn.close(); %> </table> </body> </html>
    And you'll see something like this:

    Owner First name Last name john Bugs Bunny john Elmer Fudd joe Peter Parker bill Clark Kent

    More Java Articles
    More By Vikram Vaswani and Harish Kamath, (c) Melonfire


     

       

    JAVA ARTICLES

    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway