<?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>ora-solutions.net - Martin Decker &#187; Java</title>
	<atom:link href="http://www.ora-solutions.net/web/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ora-solutions.net/web</link>
	<description>Indepented Oracle consultant</description>
	<lastBuildDate>Wed, 25 Jan 2012 14:04:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Book Review: Expert Oracle JDBC &#8211; J.R. Menon</title>
		<link>http://www.ora-solutions.net/web/2009/06/10/book-review-expert-oracle-jdbc-jr-menon/</link>
		<comments>http://www.ora-solutions.net/web/2009/06/10/book-review-expert-oracle-jdbc-jr-menon/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 09:06:36 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[10g]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle Database]]></category>

		<guid isPermaLink="false">http://www.ora-solutions.net/web/?p=685</guid>
		<description><![CDATA[I have added a new book review to my bookshelf: Expert Oracle JDBC &#8211; J.R. Menon.]]></description>
			<content:encoded><![CDATA[<p>I have added a new book review to my bookshelf: <a href="http://www.ora-solutions.net/web/bookshelf/">Expert Oracle JDBC &#8211; J.R. Menon</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ora-solutions.net/web/2009/06/10/book-review-expert-oracle-jdbc-jr-menon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JDBC Pool with Implicit Connection Cache</title>
		<link>http://www.ora-solutions.net/web/2008/12/23/jdbc-pool-with-implicit-connection-cache/</link>
		<comments>http://www.ora-solutions.net/web/2008/12/23/jdbc-pool-with-implicit-connection-cache/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 19:55:47 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[10g]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle Database]]></category>

		<guid isPermaLink="false">http://www.ora-solutions.net/web/?p=533</guid>
		<description><![CDATA[I have finally found the chance to make my first steps in Java. Instead of &#8220;Hello World&#8221;, I wanted to test the performance effect of using or NOT using a connection pool for a Java application. I have prepared 2 Java Testcases: ConnWithIcc.java: 999 Select statements with JDBC Pooling via Implicit Connection Cache Conn WithougIcc.java: [...]]]></description>
			<content:encoded><![CDATA[<p>I have finally found the chance to make my first steps in Java. Instead of &#8220;Hello World&#8221;, I wanted to test the performance effect of using or NOT using a connection pool for a Java application.</p>
<p>I have prepared 2 Java Testcases:</p>
<ul>
<li> ConnWithIcc.java: 999 Select statements with JDBC Pooling via Implicit Connection Cache</li>
<li>Conn WithougIcc.java: 999 Select statements withough JDBC Pooling</li>
</ul>
<p><strong>ConnWithIcc.java:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">oracle.jdbc.pool.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">oracle.jdbc.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ConnWithIcc
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">InterruptedException</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">ResultSet</span> rset <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Connection</span> conn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Statement</span> stmt <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">try</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// create a DataSource</span>
      OracleDataSource ods <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> OracleDataSource<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      ods.<span style="color: #006633;">setURL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jdbc:oracle:thin:@//ora-vm1:1521/ICC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      ods.<span style="color: #006633;">setUser</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;scott&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      ods.<span style="color: #006633;">setPassword</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tiger&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #666666; font-style: italic;">// set cache properties</span>
      java.<span style="color: #006633;">util</span>.<span style="color: #003399;">Properties</span> prop <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> java.<span style="color: #006633;">util</span>.<span style="color: #003399;">Properties</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      prop.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MinLimit&quot;</span>, <span style="color: #0000ff;">&quot;10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      prop.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MaxLimit&quot;</span>, <span style="color: #0000ff;">&quot;10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// set DataSource properties</span>
      ods.<span style="color: #006633;">setConnectionCachingEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// be sure set to true</span>
      ods.<span style="color: #006633;">setConnectionCacheProperties</span> <span style="color: #009900;">&#40;</span>prop<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      ods.<span style="color: #006633;">setConnectionCacheName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ImplicitCache01&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// this cache's name</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;">//System.out.println(&quot;Establishing connection &quot; +i);</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// get the connection</span>
         conn <span style="color: #339933;">=</span> ods.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #666666; font-style: italic;">//System.out.println(&quot;Connected.\nPrinting query results ...\n&quot;);</span>
         <span style="color: #666666; font-style: italic;">// Create a stmt</span>
         stmt <span style="color: #339933;">=</span> conn.<span style="color: #006633;">createStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #666666; font-style: italic;">// execute the query</span>
         <span style="color: #666666; font-style: italic;">// rset = stmt.executeQuery( &quot;select 1 from dual where &quot; + i + &quot; = &quot; + i );</span>
         rset <span style="color: #339933;">=</span> stmt.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;select 1 from dual&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>rset.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">int</span> dualnr <span style="color: #339933;">=</span> rset.<span style="color: #006633;">getInt</span> <span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         conn.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         rset.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         stmt.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/*
         try
         {
            Thread.currentThread().sleep(1000);
         }
         catch(InterruptedException ie)
         {
               System.err.println (&quot;error message: &quot; + ie.getMessage() );
               ie.printStackTrace();
               Runtime.getRuntime().exit(1);
&nbsp;
         }
         //System.out.print(&quot;\f&quot;);
*/</span>
&nbsp;
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// handle the exception properly - in this case, we just</span>
      <span style="color: #666666; font-style: italic;">// print a message and stack trace and exit the application</span>
      <span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error message: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003399;">Runtime</span>.<span style="color: #006633;">getRuntime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000000; font-weight: bold;">finally</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// close the result set, the stmt and connection.</span>
      <span style="color: #666666; font-style: italic;">// ignore any exceptions since we are in the</span>
      <span style="color: #666666; font-style: italic;">// finally clause.</span>
      <span style="color: #000000; font-weight: bold;">try</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> rset <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
           rset.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> stmt <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
           stmt.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> conn <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
           conn.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">SQLException</span> ignored <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>ignored.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>ConnWithoutIcc.java:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">oracle.jdbc.pool.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">oracle.jdbc.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ConnWithoutIcc
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">InterruptedException</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">ResultSet</span> rset <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Connection</span> conn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Statement</span> stmt <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">try</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// create a DataSource</span>
      OracleDataSource ods <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> OracleDataSource<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      ods.<span style="color: #006633;">setURL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jdbc:oracle:thin:@//ora-vm1:1521/NOICC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      ods.<span style="color: #006633;">setUser</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;scott&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      ods.<span style="color: #006633;">setPassword</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tiger&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// set cache properties</span>
      <span style="color: #666666; font-style: italic;">//java.util.Properties prop = new java.util.Properties();</span>
      <span style="color: #666666; font-style: italic;">//prop.setProperty(&quot;MinLimit&quot;, &quot;10&quot;);</span>
      <span style="color: #666666; font-style: italic;">//prop.setProperty(&quot;MaxLimit&quot;, &quot;10&quot;);</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// set DataSource properties</span>
      <span style="color: #666666; font-style: italic;">//ods.setConnectionCachingEnabled(true); // be sure set to true</span>
      <span style="color: #666666; font-style: italic;">//ods.setConnectionCacheProperties (prop);</span>
     <span style="color: #666666; font-style: italic;">// ods.setConnectionCacheName(&quot;ImplicitCache01&quot;); // this cache's name</span>
&nbsp;
&nbsp;
&nbsp;
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;">//System.out.println(&quot;Establishing connection &quot; +i);</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// get the connection</span>
         conn <span style="color: #339933;">=</span> ods.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #666666; font-style: italic;">//System.out.println(&quot;Connected.\nPrinting query results ...\n&quot;);</span>
         <span style="color: #666666; font-style: italic;">// Create a stmt</span>
         stmt <span style="color: #339933;">=</span> conn.<span style="color: #006633;">createStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #666666; font-style: italic;">// execute the query</span>
         <span style="color: #666666; font-style: italic;">// rset = stmt.executeQuery( &quot;select 1 from dual where &quot; + i + &quot; = &quot; + i );</span>
         rset <span style="color: #339933;">=</span> stmt.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;select 1 from dual&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>rset.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">int</span> dualnr <span style="color: #339933;">=</span> rset.<span style="color: #006633;">getInt</span> <span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/*
         try
         {
            Thread.currentThread().sleep(1000);
         }
         catch(InterruptedException ie)
         {
               System.err.println (&quot;error message: &quot; + ie.getMessage() );
               ie.printStackTrace();
               Runtime.getRuntime().exit(1);
&nbsp;
         }
*/</span>
         <span style="color: #666666; font-style: italic;">//System.out.print(&quot;\f&quot;);</span>
         conn.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         rset.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         stmt.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// handle the exception properly - in this case, we just</span>
      <span style="color: #666666; font-style: italic;">// print a message and stack trace and exit the application</span>
      <span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error message: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003399;">Runtime</span>.<span style="color: #006633;">getRuntime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000000; font-weight: bold;">finally</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// close the result set, the stmt and connection.</span>
      <span style="color: #666666; font-style: italic;">// ignore any exceptions since we are in the</span>
      <span style="color: #666666; font-style: italic;">// finally clause.</span>
      <span style="color: #000000; font-weight: bold;">try</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> rset <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
           rset.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> stmt <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
           stmt.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> conn <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
           conn.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">SQLException</span> ignored <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>ignored.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The first step is of course to put the java executable in the path and set the classpath environment variable:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>oracle<span style="color: #000000; font-weight: bold;">@</span>ora-vm1 ICC<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$PATH</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>kerberos<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>oracle<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>u01<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>oracle<span style="color: #000000; font-weight: bold;">/</span>product<span style="color: #000000; font-weight: bold;">/</span>10.2.0<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>u01<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>oracle<span style="color: #000000; font-weight: bold;">/</span>product<span style="color: #000000; font-weight: bold;">/</span>10.2.0<span style="color: #000000; font-weight: bold;">/</span>jre<span style="color: #000000; font-weight: bold;">/</span>1.4.2<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>u01<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>oracle<span style="color: #000000; font-weight: bold;">/</span>product<span style="color: #000000; font-weight: bold;">/</span>10.2.0<span style="color: #000000; font-weight: bold;">/</span>jdk<span style="color: #000000; font-weight: bold;">/</span>bin
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>oracle<span style="color: #000000; font-weight: bold;">@</span>ora-vm1 ICC<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$CLASSPATH</span>
.:<span style="color: #000000; font-weight: bold;">/</span>u01<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>oracle<span style="color: #000000; font-weight: bold;">/</span>product<span style="color: #000000; font-weight: bold;">/</span>10.2.0<span style="color: #000000; font-weight: bold;">/</span>jdbc<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ojdbc14.jar:<span style="color: #000000; font-weight: bold;">/</span>u01<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>oracle<span style="color: #000000; font-weight: bold;">/</span>product<span style="color: #000000; font-weight: bold;">/</span>10.2.0<span style="color: #000000; font-weight: bold;">/</span>jdbc<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>orai18n.jar</pre></td></tr></table></div>

<p>Next, you have to compile the java files into class files:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>oracle<span style="color: #000000; font-weight: bold;">@</span>ora-vm1 ICC<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ javac ConnWithoutIcc.java
<span style="color: #7a0874; font-weight: bold;">&#91;</span>oracle<span style="color: #000000; font-weight: bold;">@</span>ora-vm1 ICC<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ javac ConnWithIcc.java</pre></td></tr></table></div>

<p>Finally, we can execute both classes and measure the performance difference:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>oracle<span style="color: #000000; font-weight: bold;">@</span>ora-vm1 ICC<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #000000; font-weight: bold;">time</span> java ConnWithIcc
&nbsp;
real    0m1.501s
user    0m0.446s
sys     0m0.484s
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>oracle<span style="color: #000000; font-weight: bold;">@</span>ora-vm1 ICC<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #000000; font-weight: bold;">time</span> java ConnWithoutIcc
&nbsp;
real    0m53.653s
user    0m1.528s
sys     0m2.561s</pre></td></tr></table></div>

<p>So, the 999 &#8220;select 1 from dual&#8221; statements take about 1.5 seconds with a jdbc connection pool and take almost 1 minute without a connection pool! Moreover, if you divide 999 statements by 53.6 seconds, you get an average of 18.6 connections per second. You can easily see that one of my 2 core´s is completely utilized by 999 establishing and tear down database connections.</p>
<blockquote><pre>
[oracle@ora-vm1 ICC]$ sar -u 5 100
Linux 2.6.18-92.1.18.el5 (ora-vm1.intra)        12/23/2008

12:06:48 PM       CPU     %user     %nice   %system   %iowait    %steal     %idle
12:06:53 PM       all      0.30      0.00      1.90      2.30      0.00     95.51
12:06:58 PM       all      0.10      0.00      1.80      1.60      0.00     96.50
12:07:03 PM       all      7.51      0.00     15.92      0.70      0.00     75.88
12:07:08 PM       all     12.90      0.00     42.20      0.10      0.00     44.80
12:07:13 PM       all     13.60      0.00     40.80      0.50      0.00     45.10
12:07:18 PM       all     13.00      0.00     41.80      0.60      0.00     44.60
12:07:23 PM       all     14.09      0.00     40.16      0.40      0.00     45.35
12:07:28 PM       all     13.09      0.00     41.66      0.50      0.00     44.76
12:07:33 PM       all     13.00      0.00     41.40      0.50      0.00     45.10
12:07:38 PM       all     14.79      0.00     40.66      0.20      0.00     44.36
12:07:43 PM       all     15.02      0.00     39.84      0.30      0.00     44.84
12:07:48 PM       all     13.10      0.00     41.90      0.60      0.00     44.40
12:07:53 PM       all     14.99      0.00     40.06      0.70      0.00     44.26
12:07:58 PM       all      4.20      0.00     12.91      0.60      0.00     82.28
12:08:03 PM       all      0.30      0.00      1.50      1.00      0.00     97.20
</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.ora-solutions.net/web/2008/12/23/jdbc-pool-with-implicit-connection-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

