<?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>Vitor Rodrigues &#187; database</title>
	<atom:link href="http://www.vitorrodrigues.com/blog/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vitorrodrigues.com/blog</link>
	<description></description>
	<lastBuildDate>Sat, 26 Sep 2009 08:24:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JDBC performance tips</title>
		<link>http://www.vitorrodrigues.com/blog/2008/05/02/jdbc-performance-tips/</link>
		<comments>http://www.vitorrodrigues.com/blog/2008/05/02/jdbc-performance-tips/#comments</comments>
		<pubDate>Fri, 02 May 2008 20:30:52 +0000</pubDate>
		<dc:creator>vitor</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.vitorrodrigues.com/blog/?p=128</guid>
		<description><![CDATA[If you are into java and database development, you will find this article to be a gold mine: http://www.javaperformancetuning.com/tips/jdbc.shtml
It contains links and summary to tens of other performance articles related with java database application development.
]]></description>
			<content:encoded><![CDATA[<p>If you are into java and database development, you will find this article to be a gold mine: <a href="http://www.javaperformancetuning.com/tips/jdbc.shtml">http://www.javaperformancetuning.com/tips/jdbc.shtml</a></p>
<p>It contains links and summary to tens of other performance articles related with java database application development.</p>
<img src="http://www.vitorrodrigues.com/blog/?ak_action=api_record_view&id=128&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.vitorrodrigues.com/blog/2008/05/02/jdbc-performance-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLJ and JDBC</title>
		<link>http://www.vitorrodrigues.com/blog/2008/01/15/sqlj-and-jdbc/</link>
		<comments>http://www.vitorrodrigues.com/blog/2008/01/15/sqlj-and-jdbc/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 15:14:49 +0000</pubDate>
		<dc:creator>vitor</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[db2]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[dynamicsql]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sqlj]]></category>
		<category><![CDATA[staticsql]]></category>

		<guid isPermaLink="false">http://www.vitorrodrigues.com/blog/2008/01/15/sqlj-and-jdbc/</guid>
		<description><![CDATA[As a follow up on my last post comparing Static SQL with Dynamic SQL, I will now post an example of how to run the same code using static and dynamic SQL.
One of my visitors left a comment saying that the scope of static and dynamic SQL in Oracle is different than the one I [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">As a follow up on my last post <a href="http://www.vitorrodrigues.com/blog/2008/01/14/static-sql-vs-dynamic-sql/">comparing Static SQL with Dynamic SQL</a>, I will now post an example of how to run the same code using static and dynamic SQL.</p>
<p align="justify">One of my visitors left a comment saying that the scope of static and dynamic SQL in Oracle is different than the one I mentioned. I am not familiar at all with Oracle, but was able to find some information on their <a href="http://download.oracle.com/docs/cd/A97336_01/buslog.102/a83724/overvw1.htm#1002497">documentation </a>where they compare JDBC and SQLJ. Since their concept of static vs dynamic SQL is different from the concept in DB2, so my examples may not make sense for Oracle users. I also found out that although Oracle has had plans to desupport SQLJ in its data server, that support has been <a href="http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html">reinstated </a>in their 10g release.</p>
<p align="justify">The two code samples I will show next are shipped with DB2 (get your free copy of <a href="http://www-306.ibm.com/software/data/db2/express/">DB2 Express-C</a>) and can be found in the file <em>%DB2FOLDER%/samples/java/sqlj/TbRead.java</em>. I&#8217;ll just use one of the several examples in that file, that executes a sub-select statement in the employee table.</p>
<p>Sample code in SQLJ:</p>
<pre>#sql cur7 = {SELECT job, edlevel, SUM(comm)</pre>
<pre>	FROM employeeWHERE job IN('DESIGNER', 'FIELDREP')GROUP BY ROLLUP(job, edlevel)};</pre>
<pre>while (true){</pre>
<pre>	#sql {FETCH :cur7 INTO :job, :edlevel, :commSum};</pre>
<pre>	if (cur7.endFetch()){</pre>
<pre>		break;</pre>
<pre>	}</pre>
<pre>	System.out.print("Job: " + job + " Ed Level: " + edlevel + " Tot Comm: " +commSum);</pre>
<pre>}</pre>
<p>Sample code in JDBC:</p>
<pre>Statement stmt = con.createStatement();</pre>
<pre>ResultSet rs = stmt.executeQuery("SELECT job, edlevel, SUM(comm) "</pre>
<pre>	+"  FROM employee "</pre>
<pre>	+"  WHERE job IN('DESIGNER','FIELDREP') "</pre>
<pre>	+"  GROUP BY ROLLUP(job, edlevel)");</pre>
<pre>	while (rs.next())</pre>
<pre>	{</pre>
<pre>	if (rs.getString(1) != null)</pre>
<pre>		{</pre>
<pre>		job = rs.getString(1);</pre>
<pre>		edlevel = rs.getString(1);</pre>
<pre>		commSum = rs.getString(1);</pre>
<pre>		System.out.print("Job: " + job + " Ed Level: " + edlevel + " Tot Comm: " +commSum);</pre>
<pre>		}</pre>
<pre>	}</pre>
<p>Although both styles present different syntax, from a developer&#8217;s perspective, the only main difference is than when using JDBC one needs to explicitly fetch the row values into Java variables one by one. A common comment from Java developers is that SQLJ is not really Java (one needs to use annotations instead of java method calls), so they prefer to stick with JDBC.</p>
<p>Like I explained in <a href="http://www.vitorrodrigues.com/blog/2008/01/14/static-sql-vs-dynamic-sql/">my previous post</a>, the biggest difference between these two styles (static SQL using SQLJ and dynamic SQL using JDBC) is that the SQL statements in the SQLJ files need to be compiled and bound to the database ahead of runtime. The following diagram illustrates this process:</p>
<p><img src="http://www.vitorrodrigues.com/blog/wp-content/images/Software/Programming/SQL/staticSQL.jpg" alt="staticSQL.jpg" title="staticSQL.jpg" border="0" height="252" width="500" /></p>
<p>After the deployment process, SQLJ execution is simpler than JDBC. While JDBC statements need to be prepared at execution time, SQLJ statements are already compiled and ready to use. The two following diagrams illustrate these differences:</p>
<p><img src="http://www.vitorrodrigues.com/blog/wp-content/images/Software/Programming/SQL/jdbcstatement.jpg" alt="jdbcstatement.jpg" title="jdbcstatement.jpg" border="0" height="157" width="250" /><img src="http://www.vitorrodrigues.com/blog/wp-content/images/Software/Programming/SQL/sqljstatement.jpg" alt="sqljstatement.jpg" title="sqljstatement.jpg" border="0" height="155" width="250" /></p>
<p>As you can see, static SQL execution process is much simpler, but it requires a complex deployment process. This is an aspect of database development where there is a clash between DBAs and Developers. While ones &#8211; the DBAs &#8211; prefer the much more refined security and execution control provided by SQLJ and static SQL, others &#8211; the Developers &#8211; prefer the easier development process of dynamic SQL in the form of JDBC.</p>
<p>Soon, I will talk here about a new Java Data Access platform that supports the usage of both static and dynamic SQL at runtime (through a JVM property), allowing DBAs and Developers to use dynamic SQL on development and test environments and going with static SQL on the production environment. This way, the development community will get the best of both worlds: ease of deployment during development and testing phase and greater performance and control on the production environment.</p>
<p>If you are looking for a data management and application development tool, you should take a look at the new IBM Data Studio. It is an eclipse-based development environment, free to download and to use and with support to all major RDBMS.  Download <a href="http://www-306.ibm.com/software/data/studio/">IBM Data Studio</a>.</p>
<img src="http://www.vitorrodrigues.com/blog/?ak_action=api_record_view&id=121&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.vitorrodrigues.com/blog/2008/01/15/sqlj-and-jdbc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Static SQL vs Dynamic SQL</title>
		<link>http://www.vitorrodrigues.com/blog/2008/01/14/static-sql-vs-dynamic-sql/</link>
		<comments>http://www.vitorrodrigues.com/blog/2008/01/14/static-sql-vs-dynamic-sql/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 05:20:50 +0000</pubDate>
		<dc:creator>vitor</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[db2]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sqlj]]></category>
		<category><![CDATA[technical_articles]]></category>

		<guid isPermaLink="false">http://www.vitorrodrigues.com/blog/2008/01/14/static-sql-vs-dynamic-sql/</guid>
		<description><![CDATA[I have been wanting to write a few technical articles here on the blog, so I&#8217;ll start with something that is related with what I have been looking into at work: Static and Dynamic SQL.

From the conversations I have had with both DBAs and developers, it is clear that DBAs prefer static SQL, while developers [...]]]></description>
			<content:encoded><![CDATA[<p>I have been wanting to write a few technical articles here on the blog, so I&#8217;ll start with something that is related with what I have been looking into at work: Static and Dynamic SQL.
</p>
<p>From the conversations I have had with both DBAs and developers, it is clear that DBAs prefer static SQL, while developers prefer Dynamic SQL.
</p>
<p>The difference between static and dynamic SQL is that static SQL needs to be compiled and bound to the database before application runtime, while dynamic SQL is compiled during runtime. Next, I&#8217;ll show a list of pros and cons regarding each one.&nbsp;
</p>
<p><strong>Static SQL</strong>
</p>
<p><em><strong>Pros</strong></em>:
</p>
<ul>
<li><strong>compile at bind time</strong>. Since the statement is compiled only once and before we run our workload, we have all the database resources in order to generate the most optimal query execution plan. In DB2, there are 9 levels of optimization, being 5 the default one. When we bing our application package, we can pick the highest optimization level &#8211; 9 &#8211; and get the most optimal execution plan. Using a higher optimization level requires more resources for the compile phase, but since our workload is not yet running, we can afford this high resources requirement.</li>
<li><strong>security</strong>. Security is probably the most common reason why people use static SQL instead of dynamic SQL. Static SQL allows the DBA to set authorization at the package level. For example, consider an application package <em>app1</em>, that provides SQL functionality to select employee&#8217;s name and address from the table <em>employees</em>. The DBA can five user JOHN execution privileges on package <em>app1</em>, even if user JOHN does not have SELECT authority on table <em>employees</em>. Static SQL provides a much finer layer of security.</li>
</ul>
<p><em><strong>Cons:</strong></em>
</p>
<ul>
<li><strong>need to bind before runtime</strong>. Although binding before runtime usually allows for more optimized access plans, doing this in a test or development environment can be cumbersome.</li>
<li><strong>lack of tooling support</strong>. most of current IDEs provide coding assistance with support for APIs like JDBC. The lack of support from development tools discourages the use of static SQL.</li>
</ul>
<p><strong>Dynamic SQL</strong>
</p>
<p><em><strong>Pros</strong></em>:
</p>
<ul>
<li><strong>IDEs and APIs</strong>: using eclipse to develop Java code that interacts with the database using JDBC or JPA is much simpler than developing a SQLJ application.</li>
<li><strong>statement caching</strong>. Dynamic statement caching avoids the need to compile the same statement multiple times, increasing the performance to values close to static SQL. However, bear in mind that a cache miss will be extremely expensive.</li>
<li>
<p><strong>better statistics</strong>. Because the statement is compiled at runtime, it uses the latest statistics available, contributing to a better execution plan.<br />
    
  </p>
</li>
</ul>
<p><em><strong>Cons</strong></em>:
</p>
<ul>
<li><strong>compile at runtime</strong>. There are a few reasons why compile at runtime can be a bad thing:<br />
  </p>
<ul>
<li>every time a statement is executed, it needs to be compiled, increasing the total statement execution time</li>
<li>the compile time will account for the total execution time, so using higher optimization levels may slow down the overall performance instead of improving it.<br />
    </li>
<li>because the statement is only compiled at runtime, errors in the SQL statement won&#8217;t be detected until runtime.<br />
    </li>
</ul>
</li>
</ul>
<p>As you can see, there are several reasons why you would choose one over the other. There is no perfect solution! But if you ask me, I would suggest the following: use <strong>Static SQL if security is your main concern</strong> and use <strong>Dynamic SQL if ease of development is your main concern</strong>.
</p>
<p>
  </p>
<img src="http://www.vitorrodrigues.com/blog/?ak_action=api_record_view&id=120&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.vitorrodrigues.com/blog/2008/01/14/static-sql-vs-dynamic-sql/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Recent readings</title>
		<link>http://www.vitorrodrigues.com/blog/2007/08/07/recent-readings/</link>
		<comments>http://www.vitorrodrigues.com/blog/2007/08/07/recent-readings/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 15:49:35 +0000</pubDate>
		<dc:creator>vitor</dc:creator>
				<category><![CDATA[DB2 pureXML]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[db2]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[soa]]></category>
		<category><![CDATA[xforms]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xquery]]></category>

		<guid isPermaLink="false">http://www.vitorrodrigues.com/blog/2007/08/07/recent-readings/</guid>
		<description><![CDATA[&#160;Latest articles checked out from my &#8220;toread&#8221; folder in delicious:
  


FastSOA: Accelerate SOA with XML, XQuery, and native XML database technology 
Choosing a free database 
Where&#8217;s XML Going? 
XForms vs. Ruby on Rails 
xforms vs. ruby &#8211; a rebuttal (sort of) 

]]></description>
			<content:encoded><![CDATA[<p>&nbsp;Latest articles checked out from my &#8220;toread&#8221; folder in delicious:<br />
  
</p>
<ul>
<li><a href="http://www-128.ibm.com/developerworks/xml/library/x-accsoa/">FastSOA: Accelerate SOA with XML, XQuery, and native XML database technology</a> </li>
<li><a href="http://blogs.ittoolbox.com/database/talk/archives/choosing-a-free-database-15971">Choosing a free database</a> </li>
<li><a href="http://www.oreillynet.com/xml/blog/2007/07/wheres_xml_going.html">Where&#8217;s XML Going?</a> </li>
<li><a href="http://blog.adriaandejonge.eu/2006/12/xforms-vs-ruby-on-rails.html">XForms vs. Ruby on Rails</a> </li>
<li><a href="http://www.oreillynet.com/xml/blog/2007/03/xforms_vs_ruby_a_rebuttal_sort.html">xforms vs. ruby &#8211; a rebuttal (sort of)</a> </li>
</ul>
<img src="http://www.vitorrodrigues.com/blog/?ak_action=api_record_view&id=99&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.vitorrodrigues.com/blog/2007/08/07/recent-readings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
