Couple of Days back i started reading
Core JSP by Damon Hougland and Aaron Tavistock.
Nice book written by Damon Hougland and Aaron Tavistock.
Few important quotations i wanted to share from next two chapters (9-10).
1) What is JDBC?JDBC can be thought of as a Java interface between database applications and databases. The JDBC developers intended JDBC to become a universal way to access database data. The desired effect was to create a single set of Java objects that could be used to access any database. For the most part, JDBC is very successful at this task.
JDBC is structured around a set of Java interfaces called drivers. Each database that supports JDBC has a different set of these drivers tailored specifically to their database engine. The power of JDBC comes from the fact that the programmer does not have to know the specifics of a given database to create an application. JDBC hides the database-specific issues and gives the JSP author a single interface for talking to any JDBC supported database.
2) To achieve its single interface to multiple sets of databases, JDBC was built on three important principals. The first and foremost principle is that of simplicity. Simple and common tasks are implemented in simple interfaces. Less common or abstract tasks are achieved by extra interfaces.
Second, JDBC is built on the structured query language (SQL). SQL is by far the most common language used to manipulate information in a database. By using a standard such as SQL, JDBC is able to support many different database architectures.
3) SQL
So, if there are no functions or formulas in table entries, how is information retrieved from a database? The answer is the Structured Query Language (SQL). While there are some minor differences in syntax and usage, most major database vendors support SQL. JDBC utilizes SQL to retrieve, store, or manipulate information in a database.
Using Java code in scriplets, expressions, or JavaBeans, an SQL query is sent across the network via the JDBC API. If the SQL query returns data from the database the format is that of a table, similar to the original format of the data in the database. The returned table is not necessarily in the same format of the original table, as the SQL query can specify a specific subset of data from one or more tables.
4) The INSERT Statement
The INSERT statement is very straightforward: it inserts information into the database.As information is stored in a freeform way, there is no need to specify WHERE the information should be stored in a particular column. Thus, the format of the INSERT statement is very simple:
INSERT INTO
VALUES
5) Additionally there are optional extensions to JDBC 2.0, which are maintained under the javax.sql package.
6) Step 1: Specifying the Driver
The first step in utilizing JDBC is specifying the specific driver needed for a database.This can be done in three different ways. The first way is simplest to code, but the least often used. Within the properties file of your Java runtime environment the JDBC drivers that might be called can be specified with the " jdbc.drivers " system property.
A second method is to explicitly load the JDBC driver when needed. This is simply done in a single line of code:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
7) Step 2: Establishing the Database Connection
Once a database driver is loaded, the second step is to establish a connection to the database. This is done through the Connection object. A sample connection might look like:
Connection conn = DriverManager.getConnection(DB_URL, "Login_Name","Password");
8) Step 3: Making a Statement
Now that there is a database driver loaded and a connection to the database, there needs to be a way to send an SQL statement to the database. This is done by creating a Statement object that is created with the createStatement() method of the Connection object. For example:
Statement stmt = conn.createStatement();
9) Step 5: In Closing
While it isn't always necessary, it is always a good idea to call the close methods of the JDBC objects. This ensures that database connections are closed and resources are freed. JDBC's Statement and Connection objects each have a close() method for just this purpose:
stmt.close();
conn.close();
10) XML 101
XML stands for Extensible Markup Language, a markup language similar to HTML. Unlike HTML, which was designed to describe presentation, XML was designed to describe data. The "Extensible" part of XML means that tags are not predefined in XML. Tags must be defined for each XML page. In other words, XML is selfdescribing. XML is both a language to store data, as well as a language to describe languages. XML uses a DTD (Document Type Definition) to formally describe the data.
One of the greatest drawbacks of HTML is that all of the HTML tags are predefined.This means that HTML authors are only able to use tags that are defined in the HTML standard. XML allows authors to define their own tags and their own document structure.
12) Generating XML from JSP
Generating XML from JSP pages is nothing complex. The one key thing involved it setting the correct content type in the page directive. This is done with:
<%@ page contentType="text/xml" %>
After this point it is up to the JSP author to create output that matches the given XML language definition.
About the Authors
DAMON HOUGLAND is a Program Manager and Technical Architect for eFORCE, Inc., where he designs and develops Java enterprise applications. Previously Damon led the Web Application Infrastructure team at Lawrence Berkeley National Laboratory, which specialized in reporting scientific data through web-enabled databases and applications. He has worked as a software developer and technical manager over the last nine years.
AARON TAVISTOCK has over 10 years of experience with UNIX systems and application development. He has used his extensive knowledge of Java, JSP, and taglibs to create a leading edge web application compiler. Aaron is currently the Web Compiler Architect for Snapshop.com, Inc., a provider of B2B2C (business-to-business-to-consumer) web applications.
No comments:
Post a Comment