Saturday, April 9, 2011
Jdbc is the Application Programming Interface (API)
JDBC is the Application Programming Interface (API) designed for universal access database based on SQL. JDBC consists atsa JDBC 1.0 API that provides basic functionality for data access. JDBC 2.0 API adds to the basic functions with other advantages which more sophisticated. JDBC JDBC API is a trade mark name, not an acronym. But often mistaken for JDBC stands for Java Database Connectivity. JDBC API consists of a number of classes and interfaces written in Java which provides a standard API as a tool for programmers and provides the possibility to write database applications using any Java API. JDBC API makes it easy to send SQL statements to relational database systems and supports a variety of SQL language. Advantage JDBC API is an application can access any data source and can run on any platform that has Java Virtual Machine (JVM). So we do not have to write one program for accessing the Sybase database, Oracle or Access and others. We simply write a program that uses the JDBC API, and the program can send the SQL statement or other statement to a particular data source. With applications written in Java language one does not have to worry about writing different applications to run on different platforms. What does JDBC? JDBC technology is able to do three things: 1. Establish a connection to a data source (data source). 2. Send a statement to the source data. 3. Processing the results of the model statement 2-tier and 3-tier to access the database, JDBC API supports both 2-tier model and 3-tier. For 2-tier model, an applet or java application speaks directly to the database. In this case the required JDBC driver that can communicate to the source data. A command or statement from the user are sent to the database and the results of statements sent back to the user. The database can be located on the same machine or different from the client, which is connected to a network. If the location of the database is different from the client machine so-called client / server. Called the client user's machine and the machine where the database is called a server. This network can be a LAN or the Internet. In a 3-tier model, user send commands to a middle tier. Furthermore, middle tier sends commands to the database. Database to process the order and sends back the results to the middle tier. Then send it to the user's middle tier. The advantage of this 3-tier model is easier for deployed applications and improve performance. JDBC Driver Types JDBC API consists of two main interfaces, the first is the JDBC API for application writers, and the second is lower-level JDBC driver API for driver writers. Technology JDBC drivers can be divided into four categories: 1. JDBC-ODBC Bridge plus ODBC Driver This combination produces JDBC access via ODBC drivers. Bridging between Java applications with the Microsoft ODBC. This driver type is best suited for a corporate network where client installations are not big problems, or for server applications written in Java language in a 3-tier architecture. 2. Native API party Java technology-enabled driver converts JDBC Type this driver call into the client API for Oracle, Sybase, Informix, DB2, and other DBMS. This type requires a specific binary code of the operating system is loaded into each client. 3.Pure Driver for Database Middleware Java (JDBC-Net) Model this driver translates JDBC calls into the middleware vendor protocol, which is then translated to a DBMS protocol by a middleware server. Middleware provides connectivity to a variety of different types of databases. 4.Native-protocol Pure Java Driver Model driver converts JDBC calls directly into the network protocol used by the DBMS, allowing a direct call from a client machine to the DBMS server and providing practical solutions for Internet access.
Data Sources
// register a data source
DataSource?Class dso = new DataSource?Class(); // Implements DataSource?
dso.setServerName("SOME_SERVER");
dso.setDatabaseName("SOME_DATABASE");
Context ic = new InitialContext();
// Register dso as e named DataSource?
ic.bind("jdbc/SOME_DATABASE", dso);
...
// Querying for a DataSource?
Context ic = new InitialContext();
DataSource ds = (DataSource?) ic.lookup("jdbc/SOME_DATABASE");
// make a connection
Connection con = ds.getConnection("username", "pasword");
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment