<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Bob Duffy's Blobby Blog : JDBC</title><link>http://blogs.msdn.com/boduff/archive/tags/JDBC/default.aspx</link><description>Tags: JDBC</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>JDBC: When Good Prepared Statements go Bad</title><link>http://blogs.msdn.com/boduff/archive/2007/11/11/jdbc-when-good-prepared-statements-go-bad.aspx</link><pubDate>Sun, 11 Nov 2007 19:44:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6108062</guid><dc:creator>boduff</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/boduff/comments/6108062.aspx</comments><wfw:commentRss>http://blogs.msdn.com/boduff/commentrss.aspx?PostID=6108062</wfw:commentRss><description>&lt;p&gt;I've been doing some performance comparisons of JDBC from Java with ADO.Net from Dot.net. One key thing that jumps out at me is JDBC tends to make more use of prepared statement, even to the point of abusing the poor thing.&amp;#160; &lt;br /&gt;    &lt;br /&gt;I see some mid-tier manufacturer making bland claims like &amp;quot;Our SQL is always perfectly optimised as its prepared&amp;quot;. Oh very dear - wake up call - a Prepared statement like anything is something that is good in some scenarios and is bad in others, so using it for EVERTHING is folly.&lt;/p&gt;  &lt;p&gt;ok, so what is a prepared statement in reality? Its a way for SQL Server to repeat the same SQL Statement multiple times without having to repeat the query plan and as importantly without having to send the statement&amp;#160; down for the second and subsequent iterations. To facilitate this internally the driver will we call the stored procedure &amp;quot;exec sp_prepexec&amp;quot; to prepare the statement and return a handle to the query and then for every execution of the query we call &amp;quot;exec sp_execute @handle&amp;quot; followed by the parameters of the statement (the data). You can actually do prepared statements manually by just calling &amp;quot;sp_prepexec&amp;quot; and &amp;quot;sp_unprepare&amp;quot; although these commands are largely undocumented.&lt;/p&gt;  &lt;p&gt;From a performance point of view a prepared statement can get similar benefits as a stored procedure. This would be great, but the whole benefit of stored procedures isn't generally to do single atomic statements anyway!&lt;/p&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h2&gt;The hidden cost of Prepared Statements&lt;/h2&gt;  &lt;p&gt;Not surprisingly the hidden cost of prepared statements versus stored procedures is the fact that they need to be prepared (&lt;strong&gt;doh!).&lt;/strong&gt; From a SQL Server point of view we need to allocate a variable for every single parameter, figure out the cache plan, allocate a handle to the call, etc so the first call from SQL profiler will look something like this:     &lt;br /&gt;    &lt;br /&gt;declare @p1 int     &lt;br /&gt;set @p1=1     &lt;br /&gt;exec sp_prepexec @p1 output,N'@P0 nvarchar(4000),@P1 nvarchar(4000),@P2 nvarchar(4000),@P3 int,@P4 int,@P5 int,@P6 int,@P7 int,@P8 int,@P9 int,@P10 int,@P11 nvarchar(4000),@P12 float,@P13 float,@P14 float,@P15 int',N'INSERT INTO Sales.SalesOrderHeader (OrderDate,DueDate,ShipDate,Status,OnlineOrderFlag,CustomerID,ContactID,TerritoryID,BillToAddressID,&lt;/p&gt;  &lt;p&gt;ShipToAddressID,CreditCardID,CreditCardApprovalCode,SubTotal,TaxAmt,Freight,ShipMethodID)    &lt;br /&gt;VALUES (@P0,@P1,@P2,@P3,@P4,@P5,@P6,@P7,@P8,@P9,@P10,@P11,@P12,@P13,@P14,@P15)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; select SCOPE_IDENTITY() AS GENERATED_KEYS',N'2001-07-01T00:00:00',N'2001-07-13T00:00:00',N'2001-07-08T00:00:00',5,0,676,378,5,985,985,16281,N'105041Vi84182',&lt;/p&gt;  &lt;p&gt;24643.9362,1971.5148999999999,616.09839999999997,5    &lt;br /&gt;select @p1&lt;/p&gt;  &lt;p&gt;when we are finished we need to close the pointer to the prepared statement using &amp;quot;exec sp_unprepare @handle&amp;quot;&lt;/p&gt;  &lt;p&gt;Now I'm going to go out on a limb here and say that this is more expensive than just executing the statement in the normal way &amp;quot;INSERT INTO Table1 (C) VALUES (1)&amp;quot;, &lt;strong&gt;for a single call&lt;/strong&gt;. The real benefit is on multiple calls.&lt;/p&gt;  &lt;p&gt;Think of a prepared statement as the milli-gun in doom, takes a bit longer to spin up but when it does happy days. Not the weapon of choice for every task!&lt;/p&gt;  &lt;h2&gt;What Does a Good use of a Prepared Statement Look like&lt;/h2&gt;  &lt;p&gt;To see if your application is making good use of prepared statement you can run SQL Profiler which is install with SQL Server performance Tools. Good use of a Prepared Statement from JDBC can be seen below. We prepare once and then reuse the statement object for subsequent calls.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/boduff/WindowsLiveWriter/JDBCWhenGoodPreparedStatementsgoBad_EA76/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="284" alt="image" src="http://blogs.msdn.com/blogfiles/boduff/WindowsLiveWriter/JDBCWhenGoodPreparedStatementsgoBad_EA76/image_thumb.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h2&gt;What Does Bad use of a Prepared Statement look like&lt;/h2&gt;  &lt;p&gt;In this example we can see that the statement is prepared once per call to SQL Server resulting in more chatter to SQL Server an no real re-use of the prepared statement.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/boduff/WindowsLiveWriter/JDBCWhenGoodPreparedStatementsgoBad_EA76/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="308" alt="image" src="http://blogs.msdn.com/blogfiles/boduff/WindowsLiveWriter/JDBCWhenGoodPreparedStatementsgoBad_EA76/image_thumb_1.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h2&gt;When to NOT use prepared statements&lt;/h2&gt;  &lt;h2&gt;1) When you are closing the statement after execution.&lt;/h2&gt;  &lt;p&gt;2) When you are only executing the statement once.&lt;/p&gt;  &lt;p&gt;In a lot of development houses it is considered good practice to develop coding standards that make methods &amp;quot;stateless&amp;quot;, e.g. each method opens and closed the resources that it needs and keeps it own house clean.    &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;&lt;u&gt;This&amp;#160; renders the prepared statements useless as a tool to improve performance.&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;Like connection pooling we need to cache the statement object to get the benefit of re-using the prepared statement .&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6108062" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/boduff/archive/tags/SQL/default.aspx">SQL</category><category domain="http://blogs.msdn.com/boduff/archive/tags/JDBC/default.aspx">JDBC</category></item><item><title>Providing Feedback on the Microsoft JDBC Driver</title><link>http://blogs.msdn.com/boduff/archive/2007/11/11/providing-feedback-on-the-microsoft-jdbc-driver.aspx</link><pubDate>Sun, 11 Nov 2007 18:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6106138</guid><dc:creator>boduff</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/boduff/comments/6106138.aspx</comments><wfw:commentRss>http://blogs.msdn.com/boduff/commentrss.aspx?PostID=6106138</wfw:commentRss><description>&lt;P&gt;Thanks to everyone who was the the first Irish Java Developers Conferance (&lt;A href="http://ijtc.firstport.ie/" mce_href="http://ijtc.firstport.ie/"&gt;http://ijtc.firstport.ie&lt;/A&gt;). Hopefully there will be a repeat performance next year. Many people were surprised to see Microsoft at the event, I guess this is a sign of the times with software becoming more cross platform. Most customers&amp;nbsp;I deal with tend to have a little bit of all technologies and the real challenge is getting them to play nice togethor.&lt;/P&gt;
&lt;P&gt;To report&amp;nbsp;a bug in Microosft JDBC driver you can log on to &lt;A href="http://connect.microsoft.com/" mce_href="http://connect.microsoft.com/"&gt;http://connect.microsoft.com&lt;/A&gt;. Any feedback here automatically gets filled as a bug in&amp;nbsp;Team Foundation Server and is reviewed (triaged) at&amp;nbsp;the next&amp;nbsp;review (sometimes called war meeting). Contrary to popular belief it does not get made into a paper plane and filed into the bin!&lt;/P&gt;
&lt;P&gt;There&amp;nbsp;also a forum to get questions answered &amp;nbsp;and discuss with peers, the product team listens in and can help answer questions too.&lt;BR&gt;&lt;A href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=87&amp;amp;SiteID=1" mce_href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=87&amp;amp;SiteID=1"&gt;http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=87&amp;amp;SiteID=1&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Finally if you have any feedback of suggested improvements, you can post suggestions on the new JDBC blog site:&lt;BR&gt;&lt;A href="http://blogs.msdn.com/jdbcteam/archive/2007/11/09/jdbc-driver-feature-suggestions.aspx" mce_href="http://blogs.msdn.com/jdbcteam/archive/2007/11/09/jdbc-driver-feature-suggestions.aspx"&gt;http://blogs.msdn.com/jdbcteam/archive/2007/11/09/jdbc-driver-feature-suggestions.aspx&lt;/A&gt;&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6106138" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/boduff/archive/tags/JDBC/default.aspx">JDBC</category></item><item><title>Fog Creek Comes to Dublin</title><link>http://blogs.msdn.com/boduff/archive/2007/11/03/fog-creek-comes-to-dublin.aspx</link><pubDate>Sat, 03 Nov 2007 13:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5856356</guid><dc:creator>boduff</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/boduff/comments/5856356.aspx</comments><wfw:commentRss>http://blogs.msdn.com/boduff/commentrss.aspx?PostID=5856356</wfw:commentRss><description>&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face=Consolas size=3&gt;There's a great guest speaker coming to the IJTC (Joel Spolsky) who must be one of the most famous bloggers full stop. He wil be delivering the Key Notes for the IJTC event starting on the 8th.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face=Consolas size=3&gt;Even better there a raffle for a champagne reception with Joel nat 30,000 ft over the Irish Sea on route to London.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face=Consolas size=3&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-ansi-language: EN-IE; mso-fareast-language: EN-US; mso-fareast-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-bidi-language: AR-SA"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5856356" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/boduff/archive/tags/JDBC/default.aspx">JDBC</category></item><item><title>The Irish Java Technologies Conference</title><link>http://blogs.msdn.com/boduff/archive/2007/10/28/the-irish-java-technologies-conference.aspx</link><pubDate>Mon, 29 Oct 2007 01:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5749548</guid><dc:creator>boduff</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/boduff/comments/5749548.aspx</comments><wfw:commentRss>http://blogs.msdn.com/boduff/commentrss.aspx?PostID=5749548</wfw:commentRss><description>&lt;P&gt;The Irish Java Technologies Conference is running in Parnell Cinemas from wed 7th Nov to Fri 9th November. There is some pretty heavy hitting speakers on all things to do with Java, and the venue is excellent - beer, snacks comfy chairs and you can maybe sneak in to a movie...&lt;/P&gt;
&lt;P&gt;&lt;A href="http://ijtc.firstport.ie/" mce_href="http://ijtc.firstport.ie/"&gt;http://ijtc.firstport.ie/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am fascinated by popular&amp;nbsp;mid-tier caching technology and increased degree of object orientism in Java.&amp;nbsp;I'm often called in the pick up the mess when implementaiton of database mid tiers flop miserably on the dot.net platform (yes I have actually seen entire tables converted to collections of serialised objects in the interest of academic data abstraction, arghhhhhhhhh its like a nightmare).&lt;/P&gt;
&lt;P&gt;Anyways&amp;nbsp;we are doing a session on optimising SQL Server for the Java Platform. I'm going to focus on general SQL Server DBEngine performance best practises, the JDBC driver and SQL Programmabiltiy features to help improve performance and productiivity. Hopefully most people will&amp;nbsp;be able to pick up some tips to improve their interactivity and experience with SQL Server.&lt;/P&gt;
&lt;P&gt;I would love to hear if anyone&amp;nbsp;is currently&amp;nbsp;having or has had any performance problems with Java/JDBC and SQL Server and would be willing to share experiences and discuss. If anyone is interested, drop me an email.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5749548" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/boduff/archive/tags/SQL/default.aspx">SQL</category><category domain="http://blogs.msdn.com/boduff/archive/tags/DPE/default.aspx">DPE</category><category domain="http://blogs.msdn.com/boduff/archive/tags/JDBC/default.aspx">JDBC</category></item></channel></rss>