<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaBeat &#187; JDBC</title>
	<atom:link href="http://www.javabeat.net/category/java-j2ee/jdbc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Fri, 24 May 2013 01:32:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>New features in JDBC 3.0</title>
		<link>http://www.javabeat.net/2012/06/new-features-jdbc-3-0/</link>
		<comments>http://www.javabeat.net/2012/06/new-features-jdbc-3-0/#comments</comments>
		<pubDate>Mon, 18 Jun 2012 23:59:46 +0000</pubDate>
		<dc:creator>sraja</dc:creator>
				<category><![CDATA[JDBC]]></category>
		<category><![CDATA[JDBC 3.0]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=4363</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>This article provides an introduction to the array of core new features available in JDBC 3.0. More specifically, the features &#8216;supporting save points&#8217;, &#8216;using parameter metadata&#8217;, &#8216;updating large objects&#8217; and &#8216;auto generated keys&#8217; are discussed. Wherever possible, to get a hang of it, relevant code samples have been provided in the respective sections. Download Source [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p>This article provides an introduction to the array of core new features available in <strong><em>JDBC 3.0</em></strong>. More specifically, the features &#8216;supporting save points&#8217;, &#8216;using parameter metadata&#8217;, &#8216;updating large objects&#8217; and &#8216;auto generated keys&#8217; are discussed. Wherever possible, to get a hang of it, relevant code samples have been provided in the respective sections.</p>
<blockquote><p><strong>Download Source Code:</strong> <a class="downloadlink" href="http://www.javabeat.net/downloads/Jdbc3-NewFeatures.zip" title=" downloaded 67 times" >New Features in JDBC 3.0 (67)</a></p></blockquote>
<h2>Defining savepoints</h2>
<p>It is possible to programmatically control the creation and releasing of <strong><em>save points</em></strong> through <strong>JDBC 3.0</strong>. But before doing it, one must check whether the underlying database supports the concepts of <strong>savepoints</strong>. Save points provide multiple-level-control of database commit or rollback operations within a single transaction. For example, if two unrelated database operations have to happen with a single transaction, these two save points can be created for the very purpose. Then based on various business conditions, commit/rollback can be done to any of these save points within the same transaction. To illustrate the usage, consider the following example,</p>
<pre class="brush: java; title: ; notranslate">
package net.javabeat.jdbc3.newfeatures.savepoint;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.Savepoint;

import net.javabeat.jdbc3.newfeatures.CommonUtils;

public class SavepointTest {
 public static void main(String[] args) throws Exception{
	Connection connection = CommonUtils.getConnection();
	DatabaseMetaData databaseMetadata = connection.getMetaData();
	if (databaseMetadata.supportsSavepoints()){
		System.out.println(&quot;Savepoints supported by
		       the target database&quot;);
		processTable(connection);
	}
	}

	private static void processTable(Connection connection)
		throws Exception{
		PreparedStatement pStatement = connection.prepareStatement(&quot;
		          INSERT INTO CUSTOMER VALUES (?, ?)&quot;);
		pStatement.setInt(1, 1);
		pStatement.setString(2, &quot;New Customer&quot;);
		pStatement.execute();
		Savepoint countrySavepoint =
			connection.setSavepoint(&quot;country&quot;);
		pStatement = connection.prepareStatement(&quot;
		          INSERT INTO COUNTRY VALUES (?, ?)&quot;);
		pStatement.setInt(1, 1);
		pStatement.setString(2, &quot;India&quot;);
		// Make this transaction to fail deliberately
		connection.rollback(countrySavepoint);
		connection.commit();
	}
}
</pre>
<p>As seen from the above example, the program checks whether save points are supported by the target database by querying methods available in DatabaseMetadata. Note for save points are created by calling the method setSavePoint() defined on the Connection object. A save point can be given a name so that at a later point of time, a transaction can be made to commit or rollback based on the name. In the example code, to illustrate the usage of save point, we deliberately rollback the operation related to customer table, whereas, the changes made to country table are committed.</p>
<h2>Parameter Metadata</h2>
<p>Construction of queries for statements such as prepared statements might involve specifying dynamic values through &#8216;?&#8217;. Previously, there was no support for the tools or for the applications to identify the parameter information embedded in the queries. Now, support has been added to retrieve the parameter information that is passed to prepared statements. Please refer the below code that illustrates the usage,</p>
<pre class="brush: java; title: ; notranslate">
package net.javabeat.jdbc3.newfeatures.pmd;

import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;

import net.javabeat.jdbc3.newfeatures.CommonUtils;

public class PMDTest {
	public static void main(String[] args) throws Exception{
		Connection connection = CommonUtils.getConnection();
		PreparedStatement pStatement = connection.prepareStatement(
			&quot;INSERT INTO CUSTOMER VALUES (?, ?)&quot;);
		pStatement.setInt(1, 1);
		pStatement.setString(2, &quot;New Customer&quot;);
		ParameterMetaData parameterMetadata = pStatement.getParameterMetaData();
		int parameterCount = parameterMetadata.getParameterCount();
		for (int index = 1; index &lt;= parameterCount; index ++){
			String parameterClassName = parameterMetadata.getParameterClassName(index);
			int parameterMode = parameterMetadata.getParameterMode(index);
			String paramterTypeName = parameterMetadata.getParameterTypeName(index);
			System.out.println(parameterClassName + &quot;/&quot; + parameterMode + &quot;/&quot;
				+ &quot;/&quot; + paramterTypeName);
		}
	}
}
</pre>
<h2>Auto Generated Keys</h2>
<p>Execution of queries sometimes results in the automatic generation of fields or values for tables. The behavior is entirely dependent on the underlying database implementation. Previously, there was no standard mechanism for retrieving such information once the query is executed. Application developers are forced to use non-standard mechanisms for fetching information that happens outside the scope of query execution. For example, consider a table column containing a particular column, say &#8216;name&#8217;, and an equivalent upper column, let&#8217;s say &#8216;upper_name&#8217;. The value for the &#8216;upper_name&#8217; will be automatically populated as soon as the value is populated for the &#8216;name&#8217; column. This is one of the examples of <strong><em>auto generation feature</em></strong> and the newer specification supports this feature. Refer the code sample below,</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">
package net.javabeat.jdbc3.newfeatures.autogenkey;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.Statement;

import net.javabeat.jdbc3.newfeatures.CommonUtils;

public class AutoGeneratedKeyTest {
	public static void main(String[] args) throws Exception{
		Connection connection = CommonUtils.getConnection();
		DatabaseMetaData databaseMetadata = connection.getMetaData();
		if (databaseMetadata.supportsGetGeneratedKeys()){
			processAutoGeneratedKeys(connection);
		}
	}

	private static void processAutoGeneratedKeys(Connection connection)
		throws Exception{
		System.out.println(&quot;Auto generated keys can be retrived&quot;);
		Statement statement = connection.createStatement();
		statement.execute(&quot;INSERT INTO ADDRESSINFORMATION (ADDRESSDATA ) &quot; +
			&quot;VALUES ('Address Text')&quot;, Statement.RETURN_GENERATED_KEYS);
		ResultSet resultSet = statement.getGeneratedKeys();
		java.sql.ResultSetMetaData rsMetadata = resultSet.getMetaData();
		for (int index = 1; index &lt;= rsMetadata.getColumnCount(); index ++){
			while (resultSet.next()){
				String columnLabel = rsMetadata.getColumnName(index);
				System.out.println(resultSet.getObject(columnLabel));
			}
		}
	}

}
</pre>
<p>Note that, while executing the statement, the application has to provide indication to the underlying engine that, if any auto generation columns are applicable once the query is executed, those information have to be made available in the equivalent statement object. This is done through the method Statement.execute() where the second parameter specifies this option. Next, the method getGeneratedKeys() is added to the Statement object which returns a ResultSet containing the desired values. Because, this feature may or may not be supported by the database engine, the API supportsGeteGeneratedKeys() can be used to check the feature availability.</p>
<h2>Updating clob/blob objects</h2>
<p>The support to update clob objects is directly available on the Clob/Blob objects. The method <em>updateClob()</em> is added to the <em>ResultSet</em> object. Previously, there is no standard way to update large data objects. Note to ensure that this works and because the operation is defined on the ResultSet, the underlying ResultSet object should support updating the record. This is possible if the <em>ResultSet</em> is a flavor of <em>CONCUR_UPDATABLE</em>. Please refer the below code,</p>
<pre class="brush: java; title: ; notranslate">
package net.javabeat.jdbc3.newfeatures.clblupdate;

import java.io.StringReader;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import net.javabeat.jdbc3.newfeatures.CommonUtils;

public class ClobTest {

	public static void main(String[] args) throws Exception{
		Connection connection = CommonUtils.getConnection();
		int key = 1;
		insertClob(connection, key);
		readAndUpdateClob(connection, key);
	}

	private static void insertClob(Connection connection, int key)
		throws Exception{
		String sql = &quot;INSERT INTO CLOBTEST VALUES (?, ?)&quot;;
		PreparedStatement pStatement = connection.prepareStatement(sql);
		pStatement.setInt(1, key);
		StringReader reader = new StringReader(&quot;som big data&quot;);
		pStatement.setClob(2, reader);
		pStatement.execute();
	}

	private static void readAndUpdateClob(Connection connection, int key)
		throws Exception{
		String sql =  &quot;SELECT DATA FROM CLOBTEST WHERE ID = ?&quot;;
		PreparedStatement pStatement = connection.prepareStatement(
			sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
		pStatement.setInt(1, key);
		ResultSet resultSet = pStatement.executeQuery();
		if (resultSet.next()){
			Clob clobObject = resultSet.getClob(1);
			clobObject.setString(1, &quot;new big data&quot;);
			resultSet.updateClob(1, clobObject);
		}
	}
}
</pre>
<h2>Conclusion</h2>
<blockquote><p><strong>Download Source Code:</strong> <a class="downloadlink" href="http://www.javabeat.net/downloads/Jdbc3-NewFeatures.zip" title=" downloaded 67 times" >New Features in JDBC 3.0 (67)</a></p></blockquote>
<p>The new features in JDBC 3.0 have addressed most of the common problems that tools or developer community is encountering, thereby providing a unified way of solution. There are other minor updates done to JDBC 3.0, such as &#8216;configuring connection pools&#8217;, &#8216;adding of new data types as Boolean, Datalink, URL&#8217; etc.</p>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fcategory%2Fjava-j2ee%2Fjdbc%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/category/java-j2ee/jdbc/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/category/java-j2ee/jdbc/feed/" data-count="vertical" data-text="JDBC" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2012/06/new-features-jdbc-3-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JDBC Interview Questions</title>
		<link>http://www.javabeat.net/2009/02/jdbc-interview-questions/</link>
		<comments>http://www.javabeat.net/2009/02/jdbc-interview-questions/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 15:43:22 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[JDBC]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=406</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>11) I have the choice of manipulating database data using a byte[] or a java.sql.Blob. Which has best performance? java.sql.Blob, since it does not extract any data from the database until you explicitly ask it to. The Java platform 2 type Blob wraps a database locator (which is essentially a pointer to byte). That pointer [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>11) I have the choice of manipulating database data using a byte[] or a java.sql.Blob. Which has best performance?</h2>
<p>java.sql.Blob, since it does not extract any data from the database until you explicitly ask it to. The Java platform 2 type Blob wraps a database locator (which is essentially a pointer to byte). That pointer is a rather large number (between 32 and 256 bits in size) &#8211; but the effort to extract it from the database is insignificant next to extracting the full blob content. For insertion into the database, you should use a byte[] since data has not been uploaded to the database yet. Thus, use the Blob class only for extraction.</p>
<p><strong>Conclusion:</strong> use the java.sql.Blob class for extraction whenever you can.</p>
<h2>12) I have the choice of manipulating database data using a String or a java.sql.Clob. Which has best performance?</h2>
<p>java.sql.Clob, since it does not extract any data from the database until you explicitly ask it to. The Java platform 2 type Clob wraps a database locator (which is essentially a pointer to char). That pointer is a rather large number (between 32 and 256 bits in size) &#8211; but the effort to extract it from the database is insignificant next to extracting the full Clob content. For insertion into the database, you should use a String since data need not been downloaded from the database. Thus, use the Clob class only for extraction.</p>
<p><strong>Conclusion:</strong> Unless you always intend to extract the full textual data stored in the particular table cell, use the java.sql.Clob class for extraction whenever you can.</p>
<h2>13) Do I need to commit after an INSERT call in JDBC or does JDBC do it automatically in the DB?</h2>
<p>If your autoCommit flag (managed by the Connection.setAutoCommit method) is false, you are required to call the commit() method &#8211; and vice versa.</p>
<h2>14) How can I retrieve only the first n rows, second n rows of a database using a particular WHERE clause ? For example, if a SELECT typically returns a 1000 rows, how do first retrieve the 100 rows, then go back and retrieve the next 100 rows and so on ?</h2>
<p>Use the Statement.setFetchSize method to indicate the size of each database fetch. Note that this method is only available in the Java 2 platform. For Jdk 1.1.X and Jdk 1.0.X, no standardized way of setting the fetch size exists. Please consult the Db driver manual.</p>
<h2>15) What does ResultSet actually contain? Is it the actual data of the result or some links to databases? If it is the actual data then why can&#8217;t we access it after connection is closed?</h2>
<p>A ResultSet is an interface. Its implementation depends on the driver and hence ,what it &#8220;contains&#8221; depends partially on the driver and what the query returns.</p>
<p>For example with the Odbc bridge what the underlying implementation layer contains is an ODBC result set. A Type 4 driver executing a stored procedure that returns a cursor &#8211; on an oracle database it actually returns a cursor in the database. The oracle cursor can however be processed like a ResultSet would be from the client.</p>
<p>Closing a connection closes all interaction with the database and releases any locks that might have been obtained in the process.</p>
<h2>16) What are SQL3 data types?</h2>
<p>The next version of the ANSI/ISO SQL standard defines some new datatypes, commonly referred to as the SQL3 types. The primary SQL3 types are:</p>
<p><strong>STRUCT:</strong> This is the default mapping for any SQL structured type, and is manifest by the java.sql.Struct type.</p>
<p><strong>REF:</strong> Serves as a reference to SQL data within the database. Can be passed as a parameter to a SQL statement. Mapped to the java.sql.Ref type.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p><strong>BLOB:</strong> Holds binary large objects. Mapped to the java.sql.Blob type.</p>
<p><strong>CLOB:</strong> Contains character large objects. Mapped to the java.sql.Clob type.</p>
<p><strong>ARRAY:</strong> Can store values of a specified type. Mapped to the java.sql.Array type.</p>
<p>You can retrieve, store and update SQL3 types using the corresponding getXXX(), setXXX(), and updateXXX() methods defined in ResultSet interface</p>
<h2>17) How can I manage special characters (for example: &#8221; _ &#8216; % ) when I execute an INSERT query? If I don&#8217;t filter the quoting marks or the apostrophe, for example, the SQL string will cause an error.</h2>
<p>The characters &#8220;%&#8221; and &#8220;_&#8221; have special meaning in SQL LIKE clauses (to match zero or more characters, or exactly one character, respectively). In order to interpret them literally, they can be preceded with a special escape character in strings, e.g. &#8220;\&#8221;. In order to specify the escape character used to quote these characters, include the following syntax on the end of the query:</p>
<pre><code> <strong>{escape '<em>escape-character</em>'}</strong></code></pre>
<p>For example, the query</p>
<p><strong>SELECT NAME FROM IDENTIFIERS WHERE ID LIKE &#8216;\_%&#8217; {escape &#8216;\&#8217;} </strong></p>
<p>finds identifier names that begin with an underbar.</p>
<h2>18) What is SQLJ and why would I want to use it instead of JDBC?</h2>
<p>SQL/J is a technology, originally developed by Oracle Corporation, that enables you to embed SQL statements in Java. The purpose of the SQLJ API is to simplify the development requirements of the JDBC API while doing the same thing. Some major databases (Oracle, Sybase) support SQLJ, but others do not. Currently, SQLJ has not been accepted as a standard, so if you have to learn one of the two technologies, I recommend JDBC.</p>
<h2>19) How do I insert an image file (or other raw data) into a database?</h2>
<p>All raw data types (including binary documents or images) should be read and uploaded to the database as an array of bytes, byte[]. Originating from a binary file,</p>
<ol>
<li>Read all data from the file using a FileInputStream.</li>
<li>Create a byte array from the read data.</li>
<li>Use method setBytes(int index, byte[] data); of java.sql.PreparedStatement to upload the data.</li>
</ol>
<h2>20) How can I pool my database connections so I don&#8217;t have to keep reconnecting to the database?</h2>
<ul>
<li>you gets a reference to the pool</li>
<li>you gets a free connection from the pool</li>
<li>you performs your different tasks</li>
<li>you frees the connection to the pool</li>
</ul>
<p>Since your application retrieves a pooled connection, you don&#8217;t consume your time to connect / disconnect from your data source.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/02/jdbc-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JDBC connection in JDeveloper with MySQL database</title>
		<link>http://www.javabeat.net/2008/11/jdbc-4-0-and-oracle-jdeveloper-for-j2ee-development/</link>
		<comments>http://www.javabeat.net/2008/11/jdbc-4-0-and-oracle-jdeveloper-for-j2ee-development/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 16:10:50 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[JDBC]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=2257</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>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, [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><span style="font-size: 13px;">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. </span>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 the Java classes that may require accessing a database table in the Oracle 10g Database, or a third-party database. In this article by Deepak Vohra, we will see how to configure JDBC in the JDeveloper IDE.</p>
<p>Unlike <b>Eclipse IDE</b>, which requires a plug-in, <b>JDeveloper</b> has a built-in provision to establish a JDBC connection with a database. JDeveloper is the only Java IDE with an embedded application server, the <b>Oracle Containers for J2EE (OC4J)</b>. This database-based web application may run in <b>JDeveloper</b> without requiring a third-party application server. However, JDeveloper also supports third-party application servers. Starting with JDeveloper 11, application developers may point the IDE to an application server instance (or OC4J instance), including third-party application servers that they want to use for testing during development. <b>JDeveloper</b> provides connection pooling for the efficient use of database connections. A database connection may be used in an ADF BC application, or in a JavaEE application.</p>
<p>A database connection in <b>JDeveloper</b> may be configured in the Connections Navigator. A Connections Navigator connection is available as a <b>DataSource</b> registered with a JNDI naming service. The database connection in <b>JDeveloper</b> 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 <b>bc4j.xcfg</b> file or a JavaEE 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 <i>DataSource is an interface that represents a factory for JDBC Connection objects</i>. 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 <i>javax.sql package</i> 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 <b>data-sources.xml</b>. 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:</p>
<ul>
<li>Creating a database connection in JDeveloper Connections Navigator.</li>
<li>Configuring the Data Source and Connection Pool associated with the connection configured in the Connections Navigator.</li>
<li>The common JDBC Connection Errors</li>
<li>Before we create a JDBC connection and a data source we will discuss connection pooling and DataSource.</li>
</ul>
<h2>Connection Pooling and DataSource</h2>
<p>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:</p>
<p><b>Basic implementation:</b> In basic implementation there is 1:1 correspondence between a client&#8217;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.</p>
<p><b>Connection pooling implementation:</b> 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.</p>
<p><b>Distributed transaction implementation:</b> Distributed transaction implementation produces a Connection object that is mostly used for distributed transactions and is always connection pooled. A transaction manager implements the distributed transactions.</p>
<p>An advantage of using a data source is that code accessing a data source does not have to be modified when an application is migrated to a different application server. Only the data source properties need to be modified. A JDBC driver that is accessed with a DataSource does not register itself with a DriverManager. A DataSource object is created using a JNDI lookup and subsequently a Connection object is created from the DataSource object. For example, if a data source JNDI name is jdbc/OracleDS a DataSource object may be created using JNDI lookup. First, create an InitialContext object and subsequently create a DataSource object using the InitialContext lookup method. From the DataSource object create a Connection object using the getConnection() method:</p>
<pre class="brush: java; title: ; notranslate">
InitialContext ctx=new InitialContext();
    DataSource ds=ctx.lookup(&quot;jdbc/OracleDS&quot;);
    Connection conn=ds.getConnection();
</pre>
<p>The JNDI naming service, which we used to create a DataSource object is provided by J2EE application servers such as the Oracle Application Server Containers for J2EE (OC4J) embedded in the JDeveloper IDE.</p>
<p>A connection in a pool of connections is represented by the PooledConnection interface, not the Connection interface. The connection pool manager, typically the application server, maintains a pool of PooledConnection objects. When an application requests a connection using the DataSource.getConnection() method, as we did using the jdbc/OracleDS data source example, the connection pool manager returns a Connection object, which is actually a handle to an object that implements the PooledConnection interface.</p>
<p>A ConnectionPoolDataSource object, which is typically registered with a JNDI naming service, represents a collection of PooledConnection objects. The JDBC driver provides an implementation of the ConnectionPoolDataSource, which is used by the application server to build and manage a connection pool. When an application requests a connection, if a suitable PooledConnection object is available in the connection pool, the connection pool manager returns a handle to the PooledConnection object as a Connection object. If a suitable PooledConnection object is not available, the connection pool manager invokes the getPooledConnection() method of the ConnectionPoolDataSource to create a new PooledConnection object. For example, if connectionPoolDataSource is a ConnectionPoolDataSource object a new PooledConnection gets created as follows:</p>
<pre class="brush: java; title: ; notranslate">
PooledConnection  pooledConnection=connectionPoolDataSource.getPooledConnection();
</pre>
<p>The application does not have to invoke the getPooledConnection() method though; the connection pool manager invokes the getPooledConnection() method and the JDBC driver implementing the ConnectionPoolDataSource creates a new PooledConnection, and returns a handle to it. The connection pool manager returns a Connection object, which is a handle to a PooledConnection object, to the application requesting a connection. When an application closes a Connection object using the close() method, as follows, the connection does not actually get closed.</p>
<pre class="brush: java; title: ; notranslate">
conn.close();
</pre>
<p>The connection handle gets deactivated when an application closes a Connection object with the close() method. The connection pool manager does the deactivation. When an application closes a Connection object with the close () method any client info properties that were set using the setClientInfo method are cleared. The connection pool manager is registered with a PooledConnection object using the addConnectionEventListener() method. When a connection is closed, the connection pool manager is notified and the connection pool manager deactivates the handle to the PooledConnection object, and returns the PooledConnection object to the connection pool to be used by another application. The connection pool manager is also notified if a connection has an error. A PooledConnection object is not closed until the connection pool is being reinitialized, the server is shutdown, or a connection becomes unusable.</p>
<p>In addition to connections being pooled, <b><i>PreparedStatement</i></b> objects are also pooled by default if the database supports statement pooling. It can be discovered if a database supports statement pooling using the <b><i>supportsStatementPooling()</i></b> method of the DatabaseMetaData interface. The <b><i>PeparedStatement</i></b> pooling is also managed by the connection pool manager. To be notified of PreparedStatement events such as a <b><i>PreparedStatement</i></b> getting closed or a PreparedStatement becoming unusable, a connection pool manager is registered with a PooledConnection manager using the addStatementEventListener() method. A connection pool manager deregisters a PooledConnection object using the <b><i>removeStatementEventListener()</i></b> method. Methods <b><i>addStatementEventListener</i></b> and removeStatementEventListener are new methods in the PooledConnection interface in <b><i>JDBC 4.0</i></b>. Pooling of Statement objects is another new feature in JDBC 4.0. The Statement interface has two new methods in <b><i>JDBC 4.0</i></b> for Statement pooling: <b><i>isPoolable()</i></b> and <b><i>setPoolable()</i></b>.</p>
<p>The isPoolable method checks if a Statement object is poolable and the setPoolable method sets the Statement object to poolable. When an application closes a PreparedStatement object using the close() method the PreparedStatement object is not actually closed. The <b><i>PreparedStatement</i></b> object is returned to the pool of PreparedStatements. When the connection pool manager closes a PooledConnection object by invoking the close() method of PooledConnection all the associated statements also get closed. Pooling of PreparedStatements provides significant optimization, but if a large number of statements are left open, it may not be an optimal use of resources. Thus, the following procedure is followed to obtain a connection in an application server using a data source:</p>
<ul>
<li>1. Create a data source with a JNDI name binding to the JNDI naming service.</li>
<li>2. Create an InitialContext object and look up the JNDI name of the data source using the lookup method to create a DataSource object. If the JDBC driver implements the DataSource as a connection pool, a connection pool becomes available.</li>
<li>3. Request a connection from the connection pool. The connection pool manager checks if a suitable PooledConnection object is available. If a suitable PooledConnection object is available, the connection pool manager returns a handle to the PooledConnection object as a Connection object to the application requesting a connection.</li>
<li>4. If a PooledConnection object is not available the connection pool manager invokes the getPooledConnection() method of the ConnectionPoolDataSource, which is implemented by the JDBC driver.</li>
<li>5. The JDBC driver implementing the ConnectionPoolDataSource creates a PooledConnection object and returns a handle to it.</li>
<li>6. The connection pool manager returns a handle to the PooledConnection object as a Connection object to the application requesting a connection.</li>
<li>7. When an application closes a connection, the connection pool manager deactivates the handle to the PooledConnection object and returns the PooledConnection object to the connection pool.</li>
</ul>
<p>ConnectionPoolDataSource provides some configuration properties to configure a connection pool. The configuration pool properties are not set by the JDBC client, but are implemented or augmented by the connection pool. The properties can be set in a data source configuration. Therefore, it is not for the application itself to change the settings, but for the administrator of the pool, who also happens to be the developer sometimes, to do so. Connection pool properties supported by ConnectionPoolDataSource are discussed in following table:</p>
<p><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="ProgId" content="Word.Document" /><meta name="Generator" content="Microsoft Word 11" /><meta name="Originator" content="Microsoft Word 11" /></p>
<link href="file:///C:%5CDOCUME%7E1%5Ckrishcs%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C05%5Cclip_filelist.xml" rel="File-List" />
<style><!--
/* Font Definitions */  @font-face 	{font-family:Calibri; 	panose-1:2 15 5 2 2 2 4 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face 	{font-family:Verdana; 	panose-1:2 11 6 4 3 5 4 4 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:536871559 0 0 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin-top:0in; 	margin-right:0in; 	margin-bottom:10.0pt; 	margin-left:0in; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:Calibri; 	mso-fareast-font-family:"Times New Roman"; 	mso-bidi-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;}
--></style>
<div align="center">
<table class="MsoNormalTable" style="border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 12.9pt;">
<td style="border: 1pt solid windowtext; padding: 0in 5.4pt; width: 131.9pt; height: 12.9pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><b><span style="font-size: 10pt; font-family: Verdana; color: black;">Connection Pool Property</span></b></p>
</td>
<td style="border-style: solid solid solid none; border-color: windowtext windowtext windowtext -moz-use-text-color; border-width: 1pt 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 12.9pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><b><span style="font-size: 10pt; font-family: Verdana; color: black;">Type</span></b></p>
</td>
<td style="border-style: solid solid solid none; border-color: windowtext windowtext windowtext -moz-use-text-color; border-width: 1pt 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 12.9pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><b><span style="font-size: 10pt; font-family: Verdana; color: black;">Description</span></b></p>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">maxStatements</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">int</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Maximum number of statements the pool should keep open. 0 (zero)<br />
indicates that statement caching is not enabled.</span></p>
</td>
</tr>
<tr style="height: 24.15pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 24.15pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">initialPoolSize</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 24.15pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">int</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 24.15pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The initial number of connections the pool should have at the<br />
time of creation.</span></p>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">minPoolSize</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">int</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The minimum number of connections in the pool. 0 (zero)<br />
indicates that connections are created as required.</span></p>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">maxPoolSize</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">int</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The maximum number of connections in the connection pool. 0<br />
indicates that there is no maximum limit.</span></p>
</td>
</tr>
<tr style="height: 46.95pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 46.95pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">maxIdleTime</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 46.95pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">int</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 46.95pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Maximum duration (in seconds) a connection can be kept open<br />
without being used before the connection is closed. 0 (zero) indicates that<br />
there is no limit.</span></p>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">propertyCycle</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">int</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The interval in seconds the pool should wait before implementing<br />
the current policy defined by the connection pool properties.</span></p>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">maxStatements</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">int</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The maximum number of statements the pool can keep open. 0<br />
(zero) indicates that statement caching is not enabled.</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Setting the Environment</h2>
<p>Before getting started, we have to install the <b><i>JDeveloper 10.1.3</i></b> IDE and the <b><i>MySQL 5.0</i></b> database. Download JDeveloper from: http://www.oracle.com/technology/software/products/jdev/index.html. Download the MySQL Connector/J 5.1, the MySQL JDBC driver that supports JDBC 4.0 specification. To install <b><i>JDeveloper</i></b> extract the JDeveloper ZIP file to a directory. Log in to the MySQL database and set the database to test. Create a database table, Catalog, which we will use in a web application. The SQL script to create the database table is listed below:</p>
<pre class="brush: java; title: ; notranslate">
CREATE TABLE Catalog(CatalogId VARCHAR(25)
PRIMARY KEY, Journal VARCHAR(25), Publisher VARCHAR(25),
Edition VARCHAR(25), Title Varchar(45), Author Varchar(25));
INSERT INTO Catalog VALUES('catalog1', 'Oracle Magazine',
   'Oracle Publishing', 'Nov-Dec 2004', 'Database Resource Manager', 'Kimberly Floss');
INSERT INTO Catalog VALUES('catalog2', 'Oracle Magazine', 'Oracle Publishing',
   'Nov-Dec 2004', 'From ADF UIX to JSF', 'Jonas Jacobi');
</pre>
<p><b><i>MySQL</i></b> does not support <b><i>ROWID</i></b>, for which support has been added in JDBC 4.0. Having installed the JDeveloper IDE, next we will configure a JDBC connection in the Connections Navigator. Select the Connections tab and right-click on the Database node to select New Database Connection.</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-1.gif"><img class="aligncenter size-full wp-image-6861" alt="jdbc-1" src="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-1.gif" width="323" height="221" /></a></p>
<p>Click on Next in Create Database Connection Wizard. In the Create Database Connection Type window, specify a Connection Name—MySQLConnection for example—and set Connection Type to Third Party JDBC Driver, because we will be using MySQL database, which is a third-party database for Oracle JDeveloper and click on Next. If a connection is to be configured with Oracle database select Oracle (JDBC) as the Connection Type and click on Next.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-2.gif"><img class="aligncenter  wp-image-6862" alt="jdbc-2" src="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-2.gif" width="450" height="298" /></a></p>
<p>In the Authentication window specify Username as root (Password is not required to be specified for a root user by default), and click on Next. In the Connection window, we will specify the connection parameters, such as the driver name and connection URL; click on New to specify a Driver Class. In the Register <b><i>JDBC Driver</i></b> window, specify Driver Class as com.mysql.jdbc.Driver and click on Browse to select a Library for the Driver Class. In the Select Library window, click on New to create a new library for the <b><i>MySQL</i></b> Connector/J 5.1 JAR file. In the Create Library window, specify Library Name as <b><i>MySQL</i></b> and click on Add Entry to add a JAR file entry for the MySQL library. In the Select Path Entry window select <b><i>mysql-connector-java-5.1.3-rcmysql-connector-java-5.1.3-rc-bin.jar</i></b> and click on Select. In the Create Library window, after a Class Path entry gets added to the MySQL library, click on OK. In the Select Library window, select the MySQL library and click on OK. In the Register JDBC Driver window, the MySQL library gets specified in the Library field and the <b><i>mysql-connector-java-5.1.3-rcmysql-connector-java-5.1.3-rc-bin.jar</i></b> gets specified in the Classpath field. Now, click on OK. The Driver Class, Library, and Classpath fields get specified in the Connection window. Specify URL as jdbc:mysql://localhost:3306/test, and click on Next.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-3.gif"><img class="aligncenter  wp-image-6863" alt="jdbc-3" src="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-3.gif" width="450" height="296" /></a></p>
<p>In the Test window click on Test Connection to test the connection that we have configured. A connection is established and a success message gets output in the Status text area. Click on Finish in the Test window. A connection configuration, MySQLConnection, gets added to the Connections navigator.</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-4.gif"><img class="aligncenter size-full wp-image-6864" alt="jdbc-4" src="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-4.gif" width="280" height="294" /></a></p>
<p>The connection parameters are displayed in the structure view. To modify any of the connection settings, double-click on the Connection node. The Edit Database Connection window gets displayed. The connection Username, Password, Driver Class, and URL may be modified in the Edit window. A database connection configured in the Connections navigator has a JNDI name binding in the JNDI naming service provided by OC4J. Using the JNDI name binding, a DataSource object may be created in a J2EE application. To view, or modify the configuration settings of the JDBC connection select Tools | Embedded OC4J Server Preferences in JDeveloper. In the window displayed, select Global | Data Sources node, and to update the data-sources.xml file with the connection defined in the Connections navigator, click on the Refresh Now button. Checkboxes may be selected to Create data-source elements where not defined, and to Update existing data-source elements.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-5.gif"><img class="aligncenter  wp-image-6865" alt="jdbc-5" src="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-5.gif" width="450" height="320" /></a></p>
<p>The connection pool and data source associated with the connection configured in the Connections navigator get listed. Select the jdev-connection-pool-MySQLConnection node to list the connection pool properties as Property Set A and Property Set B.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-6.gif"><img class="aligncenter  wp-image-6866" alt="jdbc-6" src="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-6.gif" width="450" height="320" /></a></p>
<p>The tuning properties of the JDBC connection pool may be set in the Connection Pool window. The different tuning attributes are listed in following table:</p>
<p><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="ProgId" content="Word.Document" /><meta name="Generator" content="Microsoft Word 11" /><meta name="Originator" content="Microsoft Word 11" /></p>
<link href="file:///C:%5CDOCUME%7E1%5Ckrishcs%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C05%5Cclip_filelist.xml" rel="File-List" />
<style><!--
/* Font Definitions */  @font-face 	{font-family:Calibri; 	panose-1:2 15 5 2 2 2 4 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face 	{font-family:Verdana; 	panose-1:2 11 6 4 3 5 4 4 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:536871559 0 0 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin-top:0in; 	margin-right:0in; 	margin-bottom:10.0pt; 	margin-left:0in; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:Calibri; 	mso-fareast-font-family:"Times New Roman"; 	mso-bidi-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;}
--></style>
<div align="center">
<table class="MsoNormalTable" style="border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 12.9pt;">
<td style="border: 1pt solid windowtext; padding: 0in 5.4pt; width: 131.9pt; height: 12.9pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><b><span style="font-size: 10pt; font-family: Verdana; color: black;">Tuning Attribute</span></b></p>
</td>
<td style="border-style: solid solid solid none; border-color: windowtext windowtext windowtext -moz-use-text-color; border-width: 1pt 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 12.9pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><b><span style="font-size: 10pt; font-family: Verdana; color: black;">Attribute Description</span></b></p>
</td>
<td style="border-style: solid solid solid none; border-color: windowtext windowtext windowtext -moz-use-text-color; border-width: 1pt 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 12.9pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><b><span style="font-size: 10pt; font-family: Verdana; color: black;">Default Value</span></b></p>
</td>
</tr>
<tr style="height: 46.95pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 46.95pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Abandoned Connection Timeout</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 46.95pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Interval (seconds) after which a connection acquired by a user<br />
that has been inactive is returned to the cache.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 46.95pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">-1 implies that the feature is not in effect.</span></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Retry Interval</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Interval (seconds) after which a failed connection attempt is<br />
retried. Used with Max Connect Attempts.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">1</span></p>
</td>
</tr>
<tr style="height: 58.35pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 58.35pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Disable Connection Pooling</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 58.35pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Specifies if application server&#8217;s connection pooling is to be<br />
disabled. This attribute is available because some drivers provide connection<br />
pooling inside the driver.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 58.35pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">False</span></p>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Inactivity Timeout</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The number of seconds of inactivity after which an unused<br />
connection is removed from the pool.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Inactivity Timeout</span></p>
</td>
</tr>
<tr style="height: 81.15pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 81.15pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Initial Limit</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 81.15pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The initial number of connections in the connection pool. If<br />
value is greater than 0, the specified number of connections are pre-created<br />
and available in the connection cache, thus reducing the time required to<br />
build the cache to its optimal size.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 81.15pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">0</span></p>
</td>
</tr>
<tr style="height: 58.35pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 58.35pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Login Timeout</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 58.35pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The number of seconds after which a login attempt is timed out.<br />
0 implies that the system timeout value is used. If a system timeout is not<br />
defined, a login attempt is not timed out.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 58.35pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">0</span></p>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Max Connect Attempts</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The maximum number of connection attempts to a database. Used in<br />
conjunction with retry interval.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 35.55pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">3</span></p>
</td>
</tr>
<tr style="height: 58.35pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 58.35pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Max Connections</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 58.35pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The maximum number of available database connections in the<br />
connection pool. A value of 0 or less implies that there is no maximum limit.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 58.35pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">0</span></p>
</td>
</tr>
<tr style="height: 24.15pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 131.9pt; height: 24.15pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Min Connections</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 24.15pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">The minimum number of database connections in the connection<br />
pool.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 131.9pt; height: 24.15pt;" valign="top" width="176">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">0</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p>Select Property Set B to specify additional connection pool properties.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-7.gif"><img class="aligncenter  wp-image-6867" alt="jdbc-7" src="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-7.gif" width="450" height="320" /></a></p>
<p>The connection pool properties in Property Set B are discussed in the following table:</p>
<p><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="ProgId" content="Word.Document" /><meta name="Generator" content="Microsoft Word 11" /><meta name="Originator" content="Microsoft Word 11" /></p>
<link href="file:///C:%5CDOCUME%7E1%5Ckrishcs%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C05%5Cclip_filelist.xml" rel="File-List" />
<style><!--
/* Font Definitions */  @font-face 	{font-family:Calibri; 	panose-1:2 15 5 2 2 2 4 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face 	{font-family:Verdana; 	panose-1:2 11 6 4 3 5 4 4 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:536871559 0 0 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin-top:0in; 	margin-right:0in; 	margin-bottom:10.0pt; 	margin-left:0in; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:Calibri; 	mso-fareast-font-family:"Times New Roman"; 	mso-bidi-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;}
--></style>
<div align="center">
<table class="MsoNormalTable" style="width: 6in; border-collapse: collapse;" width="576" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 12.9pt;">
<td style="border: 1pt solid windowtext; padding: 0in 5.4pt; width: 126.55pt; height: 12.9pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><b><span style="font-size: 10pt; font-family: Verdana; color: black;">Property</span></b></p>
</td>
<td style="border-style: solid solid solid none; border-color: windowtext windowtext windowtext -moz-use-text-color; border-width: 1pt 1pt 1pt medium; padding: 0in 5.4pt; width: 126.55pt; height: 12.9pt;" colspan="2" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><b><span style="font-size: 10pt; font-family: Verdana; color: black;">Description</span></b></p>
</td>
<td style="border-style: solid solid solid none; border-color: windowtext windowtext windowtext -moz-use-text-color; border-width: 1pt 1pt 1pt medium; padding: 0in 5.4pt; width: 126.75pt; height: 12.9pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><b><span style="font-size: 10pt; font-family: Verdana; color: black;">Default Value</span></b></p>
</td>
</tr>
<tr style="height: 58.35pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 126.55pt; height: 58.35pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Num Cached Statements</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.55pt; height: 58.35pt;" colspan="2" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Specifies the maximum number of prepared and callable statements<br />
that should be cached for each connection in each connection pool. Statement<br />
caching increases system performance. A value greater than 0 enables<br />
statement caching.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.75pt; height: 58.35pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">0</span></p>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 126.55pt; height: 35.55pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Property Check Interval</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.55pt; height: 35.55pt;" colspan="2" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Specifies the time interval (seconds) after which property<br />
values are checked for new values, and time out limits are implemented.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.75pt; height: 35.55pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">900</span></p>
</td>
</tr>
<tr style="height: 46.95pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 126.55pt; height: 46.95pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Time to Live Timeout</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.55pt; height: 46.95pt;" colspan="2" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Specifies the maximum number of seconds a used connection may be<br />
active, after which it is closed and returned to the connection pool. -1<br />
indicates that the feature is not enabled.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.75pt; height: 46.95pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">-1</span></p>
</td>
</tr>
<tr style="height: 69.75pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 126.9pt; height: 69.75pt;" colspan="2" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Used Connection Wait Timeout</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.2pt; height: 69.75pt;" valign="top" width="168">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Number of seconds for which a used connection remains unused<br />
before being returned to the connection pool. Only applies if the maximum<br />
numbers of connections that a connection pool may cache have been acquired by<br />
clients, and a client requests a connection.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.75pt; height: 69.75pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">60</span></p>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 126.9pt; height: 35.55pt;" colspan="2" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Validate Connections</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.2pt; height: 35.55pt;" valign="top" width="168">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Specifies if connections are to be validated, when given to a<br />
client. Used in conjunction with Validate Connection Statements.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.75pt; height: 35.55pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">False</span></p>
</td>
</tr>
<tr style="height: 35.55pt;">
<td style="border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; border-width: medium 1pt 1pt; padding: 0in 5.4pt; width: 126.9pt; height: 35.55pt;" colspan="2" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Validate Connection Statements</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.2pt; height: 35.55pt;" valign="top" width="168">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">Specifies the SQL statements used to validate connections before<br />
being acquired by a client.</span></p>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0in 5.4pt; width: 126.75pt; height: 35.55pt;" valign="top" width="169">
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 10pt; font-family: Verdana; color: black;">None</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p>The Connection Factory node specifies the Factory Class, User name, Password, Login Timeout, and connection URL. The factory class must implement one of the following interfaces: java.sql.Driver, javax.sql.DataSource, javax.sql.ConnectionPoolDataSource, javax.sql.XADataSource.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-8.gif"><img class="aligncenter  wp-image-6868" alt="jdbc-8" src="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-8.gif" width="450" height="320" /></a></p>
<p>The Managed DataSource node specifies the managed data sources associated with the connection, and which are data sources managed by the OC4J. A managed data source is an OC4J implementation of the javax.sql.DataSource interface that wraps a JDBC driver class, or data source class. Even if the factory class does not implement the javax.sql.DataSource interface, the OC4J implementation of the factory class implements the javax.sql.DataSource interface. A managed data source supports connection caching, global transaction management, and error handling, all provided by the OC4J. A managed data source is associated with a connection pool, and thus has the advantage of being able to specify the tuning parameters. The JNDI Name of the data source is specified in the managed data source window. The JNDI Name is in the jdbc/MySQLConnectionDS format, with MySQLConnection being the connection name configured in the Connections navigator.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-9.gif"><img class="aligncenter  wp-image-6869" alt="jdbc-9" src="http://www.javabeat.net/wp-content/uploads/2008/11/jdbc-9.gif" width="450" height="321" /></a></p>
<p>A connection MySQLConnection in the Connections navigator is available as a data source with the JNDI Name binding jdbc/MySQLConnectionDS. To obtain a connection from the data source, add a resource-ref element to the web application in which a connection is to be obtained. In a Servlet or JSP application, a connection may be obtained with the data source JNDI Name.</p>
<pre class="brush: java; title: ; notranslate">
InitialContext initialContext = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)
initialContext.lookup(&quot;java:comp/env/jdbc/MySQLConnectionDS&quot;);
java.sql.Connection conn = ds.getConnection();
</pre>
<p>JavaEE 5 defines annotations to support resource injection. Resource injection is the injection of external resources, such as a data source in a JEE 5 application using the javax.annotation.Resource annotation. JDeveloper 11 will support resource injection with annotations to obtain a handle of a data source. For example, define a catalogDS resource of the javax.sql.DataSource type, as shown below:</p>
<pre class="brush: java; title: ; notranslate">
private @Resource DataSource catalogDS;
</pre>
<p>The catalogDS field of type javax.sql.DataSource is annotated with the @Resource annotation. JNDI lookup is not required with resource injection, and the DataSource resource is also not defined in the web.xml deployment descriptor.</p>
<h2>JDBC Configuration Errors</h2>
<p>You might get errors while configuring a <b><i>JDBC</i></b> connection. If you are using <b><i>MySQL</i></b>, and the connection URL is incorrect, or the <b><i>MySQL</i></b> database is not running, the following error message is generated:</p>
<p><b>Communications link failure</b></p>
<p>If you are using Oracle database, some possible connection configuration errors are listed below:</p>
<p><b>IO exception: The Network Adapter could not establish the connectionM</b><br />
<b>IO exception: Connection refused</b></p>
<p>The Network Adapter could not establish the connection exception is caused by one or more of the following configuration errors:</p>
<ul>
<li>1. The database host name, port number, or database instance name is wrong.</li>
<li>2. The database TNSListener has not been started. The TNSListener may be started with the lsnrctl utility.</li>
</ul>
<pre class="brush: java; title: ; notranslate">
C:&amp;gt;lsnrctl start
The Connection refused exception is caused by one or more of the following configuration errors:
1.	The database SID specified is incorrect.
2.	The database instance has not been started. To start the database instance connect to SQL*Plus as SYSDBA.
C:&amp;gt;sqlplus SYS/&amp;lt;pwd&amp;gt; AS SYSDBA
At the SQL prompt, start the database instance with the startup command.
SQL&amp;gt;startup
</pre>
<h2>Summary</h2>
<p><b><i>JDeveloper IDE</i></b> provides a built-in Connections navigator to configure a connection with any relational database for which a JDBC driver is available. A connection configured in the Connections navigator is also available as a data source. In this article, we have configured a <b><i>JDBC</i></b> connection in JDeveloper with <b><i>MySQL</i></b> database using the <b><i>MySQL Connector/J 5.1 JDBC 4.0</i></b> driver.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2008/11/jdbc-4-0-and-oracle-jdeveloper-for-j2ee-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
