<?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>How To ... &#187; jdbc</title>
	<atom:link href="http://howto.tawaret.com/t/jdbc/feed/" rel="self" type="application/rss+xml" />
	<link>http://howto.tawaret.com</link>
	<description></description>
	<lastBuildDate>Fri, 27 May 2011 08:53:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Retrieving identity column values from MS SQL Server by JDBC</title>
		<link>http://howto.tawaret.com/retrieving-identity-column-values-from-ms-sql-server-by-jdbc/</link>
		<comments>http://howto.tawaret.com/retrieving-identity-column-values-from-ms-sql-server-by-jdbc/#comments</comments>
		<pubDate>Wed, 03 Jan 2007 18:43:46 +0000</pubDate>
		<dc:creator>pjdc</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[sql server]]></category>

		<guid isPermaLink="false">http://howto.tawaret.com/index.php/retrieving-identity-column-values-from-ms-sql-server-by-jdbc/</guid>
		<description><![CDATA[Retrieving identity column values in JDBC applications: You define an identity column in a CREATE TABLE by specifying the IDENTITY clause when you define a column. This feature is defined in the JDBC, and implmented in the MS Sql Server 2005, not in the older version. For Oracle database this is not implemented, but the [...]]]></description>
			<content:encoded><![CDATA[<h3 id="tjvjdidn"><strong>Retrieving identity column values in  JDBC applications:</strong></h3>
<p>You define an <span id="changed" />identity column in a CREATE TABLE  by specifying the <span id="changed" /> IDENTITY clause when you define a column.<br />
This feature is defined in the JDBC, and implmented in the MS Sql Server 2005, not in the older version. For Oracle database this is not implemented, but the common solution of the rownum can be used instead.</p>
<p>1.Set the prepared statement to get the identity column from DB:</p>
<pre lang="java">Connection.prepareStatement(sql-statement,
Statement.RETURN_GENERATED_KEYS);</pre>
<p>or</p>
<pre lang="java">Statement.executeUpdate(sql-statement, Statement.RETURN_GENERATED_KEYS);</pre>
<p>2. Get the generated values from the statement</p>
<pre lang="java">rs = stmt.getGeneratedKeys();
while (rs.next()) {
rs.getBigDecimal(1);
}</pre>
<p>Technorati Tags: <a rel="tag" class="performancingtags" href="http://technorati.com/tag/ms%20sql%20server">ms sql server</a>, <a rel="tag" class="performancingtags" href="http://technorati.com/tag/jdbc">jdbc</a>, <a rel="tag" class="performancingtags" href="http://technorati.com/tag/identity">identity</a></p>
]]></content:encoded>
			<wfw:commentRss>http://howto.tawaret.com/retrieving-identity-column-values-from-ms-sql-server-by-jdbc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

