See which of your colleagues or former colleagues are already on Java Link: Check out the Contact Finder
News »Browse Articles » Configuring JDBC in Oracle JDeveloper
+1
Vote Vote

Configuring JDBC in Oracle JDeveloper

Views 5 Views    Comments 0 Comments    Share Share    Posted 16-05-2009  
The Java Database Connectivity (JDBC) API is used to access a SQL database from a Java application. JDBC also supports tabular data sources, such as a spreadsheet.

Oracle JDeveloper is a free Integrated Development Environment (IDE) for modeling, developing, debugging, optimizing, and deploying Java applications. JDeveloper 10g is used to develop J2EE applications comprising the JSPs, EJBs, struts, servlets, and Java classes that may require accessing a database table in an Oracle 10g Database or a third-party database. In this extract from the book JDBC 4.0 and Oracle JDeveloper for J2EE Development (Packt Publishing), we will see how to configure JDBC in the JDeveloper IDE.

Unlike the Eclipse IDE, which requires a plug-in, JDeveloper has a built-in provision to establish a JDBC connection with a database. JDeveloper is the only Java IDE with an embedded application server, Oracle Containers for J2EE (OC4J) or WebLogic Server in JDeveloper 11g. Thus a database-based Web application may run in JDeveloper without a third-party application server. However, JDeveloper also supports third-party application servers. Starting with JDeveloper 11, application developers can point the IDE to an application server instance, including third-party application servers, that you want to use for testing during development. JDeveloper provides connection pooling for the efficient use of database connections. A database connection may be used in an ADF BC (Business Components) application or in a Java EE application.

A database connection in JDeveloper may be configured in the Connections Navigator. A Connections Navigator connection is available as a DataSource registered with a JNDI naming service. The database connection in JDeveloper is a reusable named connection that developers configure once and then use in as many of their projects as they want. Depending on the nature of the project and the database connection, the connection is configured in the bc4j.xcfg file or a Java EE data source. Here, it is necessary to distinguish between data source and DataSource. A data source is a source of data; for example, an RDBMS database is a data source. A DataSource is an interface that represents a factory for JDBC Connection objects.

JDeveloper uses the term Data Source or data source to refer to a factory for connections. We will also use the term Data Source or data source to refer to a factory for connections, which in the javax.sql package is represented by the DataSource interface. A DataSource object may be created from a data source registered with the JNDI (Java Naming and Directory) naming service using JNDI lookup. A JDBC Connection object may be obtained from a DataSource object using the getConnection method. As an alternative to configuring a connection in the Connections Navigator, a data source may also be specified directly in the data source configuration file data-sources.xml.

In this article we will discuss the procedure to configure a JDBC connection and a JDBC data source in JDeveloper 10g IDE. We will use the MySQL 5.0 database server and MySQL Connector/J 5.1 JDBC driver, which support the JDBC 4.0 specification. In this article you will learn the following:

Creating a database connection in JDeveloper Connections Navigator.

Configuring the Data Source and Connection Pool associated with the connection configured in the Connections Navigator.

The common JDBC Connection Errors.

Before we create a JDBC connection and a data source we will discuss connection pooling and DataSource.

Connection Pooling and DataSource

The javax.sql package provides the API for server-side database access. The main interfaces in the javax.sql package are DataSource, ConnectionPoolDataSource, and PooledConnection. The DataSource interface represents a factory for connections to a database. DataSource is a preferred method of obtaining a JDBC connection. An object that implements the DataSource interface is typically registered with a Java Naming and Directory API-based naming service. DataSource interface implementation is driver-vendor specific. The DataSource interface has three types of implementations:

Basic implementation: In a basic implementation there is a 1:1 correspondence between a client`s Connection object and the connection with the database. This implies that for every Connection object, there is a connection with the database. With the basic implementation, the overhead of opening, initiating, and closing a connection is incurred for each client session.

Connection pooling implementation: A pool of Connection objects is available from which connections are assigned to the different client sessions. A connection pooling manager implements the connection pooling. When a client session does not require a connection, the connection is returned to the connection pool and becomes available to other clients. Thus, the overheads of opening, initiating, and closing connections are reduced....

Source:
http://java.sys-con.com/node/961861
+1
Vote  Vote
Enter your comment:
No Comments For This News

Search News

What's the News?

Post a link to something interesting from another site, or submit your own original writing for the Java community to read.

Most Popular News

Most Recent User Submitted News