MAKING DATABASE CONNECTIONS USING DATASOURCE in Font

Creating PDF 417 in Font MAKING DATABASE CONNECTIONS USING DATASOURCE

CHAPTER 4 MAKING DATABASE CONNECTIONS USING DATASOURCE
Encoding PDF-417 2d Barcode In None
Using Barcode generator for Font Control to generate, create PDF-417 2d barcode image in Font applications.
www.OnBarcode.com
Make UPC - 13 In None
Using Barcode generation for Font Control to generate, create GS1 - 13 image in Font applications.
www.OnBarcode.com
When connecting to a data source (a relational database such as MySQL or Oracle) using a DataSource object registered with a JNDI naming service rather than using the DriverManager facility, you get three benefits: It makes code more portable. It makes code much easier to maintain. You get the benefit of connection pooling. For details on these benefits, refer to JDBC API Tutorial and Reference, Third Edition (AddisonWesley, 2003) by Maydene Fisher, Jon Ellis, and Jonathan Bruce. JDBC 2.0 introduced a DataSource interface that eliminates connection URLs and driver names in your Java applications. DataSource enables you to register (using JNDI API) instances of DataSource with a unique name; then, other applications can retrieve the registered DataSource using the unique name. A DataSource object provides a new method for JDBC clients to obtain a DBMS connection (represented as java.sql.Connection). A DataSource object is usually created, deployed (that is, registered), located (lookup operation), and managed separately from the Java applications that use it. Figure 4-1 shows the life cycle of a DataSource object.
EAN128 Creation In None
Using Barcode drawer for Font Control to generate, create EAN 128 image in Font applications.
www.OnBarcode.com
UPC Symbol Drawer In None
Using Barcode creation for Font Control to generate, create UCC - 12 image in Font applications.
www.OnBarcode.com
Figure 4-1. Life cycle of a DataSource object
Barcode Maker In None
Using Barcode printer for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
DataMatrix Maker In None
Using Barcode encoder for Font Control to generate, create ECC200 image in Font applications.
www.OnBarcode.com
In this figure, note that the Directory and Naming Service item is JNDI-enabled and can bind/ register and hold any number of DataSource objects. Most databases can use CORBA-based naming and directory services, but in order not to tie yourself into a specific implementation of JNDI, in this chapter you will see how to use a file system based reference implementation of a JNDI SPI driver from JavaSoft. In real production applications, you should select a commercially available naming and directory service product (such as Sun s Directory Server, Novell s Directory Server, and so on). One Java application (Java Application 1) can create a data source (using some data source configuration from an XML file, a relational database, or a file-based system). Also, Java Application 1 can register (or bind) and manage the created data source. In registering a data source, you have to associate the data source with a unique key. Once the data source is registered, it is accessible to other applications (such as Java Application 2). Java Application 2 can get registered data sources
Drawing PDF-417 2d Barcode In None
Using Barcode encoder for Font Control to generate, create PDF-417 2d barcode image in Font applications.
www.OnBarcode.com
Print 4-State Customer Barcode In None
Using Barcode creator for Font Control to generate, create USPS Intelligent Mail image in Font applications.
www.OnBarcode.com
CHAPTER 4 MAKING DATABASE CONNECTIONS USING DATASOURCE
Creating PDF-417 2d Barcode In Java
Using Barcode generation for Android Control to generate, create PDF-417 2d barcode image in Android applications.
www.OnBarcode.com
PDF-417 2d Barcode Reader In C#
Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
using a lookup method by providing the unique key. Some vendors (such as BEA s WebLogic and IBM s WebSphere) provide tools for deploying DataSource objects and then provide browsing/ lookup operations to get the DataSource objects.
Code 39 Full ASCII Encoder In .NET
Using Barcode generation for .NET Control to generate, create USS Code 39 image in .NET framework applications.
www.OnBarcode.com
Encoding Code 3 Of 9 In None
Using Barcode creator for Microsoft Excel Control to generate, create Code39 image in Microsoft Excel applications.
www.OnBarcode.com
4-2. How Do You Create a DataSource Object
USS Code 39 Generator In None
Using Barcode printer for Office Word Control to generate, create Code39 image in Microsoft Word applications.
www.OnBarcode.com
Data Matrix ECC200 Generation In Visual C#
Using Barcode drawer for .NET Control to generate, create Data Matrix 2d barcode image in .NET framework applications.
www.OnBarcode.com
To create a DataSource object, you define it with a vendor-specific Java class, which implements the DataSource interface. For the sake of this discussion, assume that DBVendorDataSource (which is a vendor-specific Java class) implements the DataSource interface. Then you can create a DataSource object by writing the following code: // // generic solution // DBVendorDataSource vendorDataSource = new DBVendorDataSource(); vendorDataSource.setServerName("saratoga"); vendorDataSource.setDatabaseName("payrollDatabase"); vendorDataSource.setDescription("the data source for payroll"); // // you can set other attributes by using vendorDataSource.setXXX(...) // // now cast it to DataSource DataSource payrollDS = (DataSource) vendorDataSource;
Make Code 3 Of 9 In None
Using Barcode creator for Software Control to generate, create Code-39 image in Software applications.
www.OnBarcode.com
Creating Barcode In VS .NET
Using Barcode printer for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
4-3. How Do You Create a DataSource Object Using Oracle
Code 128 Code Set C Drawer In Java
Using Barcode creator for Java Control to generate, create USS Code 128 image in Java applications.
www.OnBarcode.com
Draw GS1 128 In .NET Framework
Using Barcode printer for Reporting Service Control to generate, create EAN 128 image in Reporting Service applications.
www.OnBarcode.com
To create a DataSource object using the Oracle database, you should use the (vendor-specific) OracleDataSource class (defined in the oracle.jdbc.pool package and available from Oracle). You can create a DataSource object by writing the following code: import oracle.jdbc.pool.OracleDataSource; import javax.sql.DataSource; ... OracleDataSource oracleDataSource = new OracleDataSource(); oracleDataSource.setServerName("saratoga"); oracleDataSource.setDatabaseName("payrollDatabase"); oracleDataSource.setDescription("the data source for payroll"); // // you can set other attributes by // invoking oracleDataSource.setXXX(...) // // now cast it to DataSource DataSource payrollDS = (DataSource) oracleDataSource;
Barcode Drawer In Java
Using Barcode printer for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
Encode Barcode In None
Using Barcode printer for Online Control to generate, create Barcode image in Online applications.
www.OnBarcode.com
4-4. How Do You Create a DataSource Object Using MySQL
To create a DataSource object using the MySQL database, you should use the (vendor-specific) MySQLDataSource class. You can create a DataSource object by writing the following code: import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; import javax.sql.DataSource; ... MysqlDataSource mysqlDataSource = new MysqlDataSource(); mysqlDataSource.setServerName("saratoga");
CHAPTER 4 MAKING DATABASE CONNECTIONS USING DATASOURCE
mysqlDataSource.setDatabaseName("payrollDatabase"); mysqlDataSource.setDescription("the data source for payroll"); // // NOTE: you can set other attributes by // invoking mysqlDataSource.setXXX( ) // // now cast it to DataSource DataSource payrollDS = (DataSource) mysqlDataSource;
4-5. How Do You Create a DataSource Object Using a Relational Database (Oracle/MySQL)
To create a DataSource object using an Oracle, MySQL, Sybase, or DB2 database, you introduce a vendor parameter. (The vendor parameter uniquely identifies a specific database such as Oracle, MySQL, or Sybase.) Depending on the vendor parameter, you apply a different implementation class for creating a DataSource object. For example, if vendor equals oracle, then you select the OracleDataSource class, and if vendor equals mysql, then you select the MysqlDataSource class; otherwise, you return null. (In addition, you can modify this to support more than two vendors.)
Copyright © OnBarcode.com . All rights reserved.