<?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>Roger Cuddy &#187; Derby</title>
	<atom:link href="http://www.rogercuddy.com/tag/derby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rogercuddy.com</link>
	<description>This site just holds copies of whatever I&#039;ve posted around the net. YMMV</description>
	<lastBuildDate>Wed, 20 Jul 2011 03:59:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Combining Derby embedded mode and server mode</title>
		<link>http://www.rogercuddy.com/programming/combining-derby-embedded-mode-and-server-mode/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/combining-derby-embedded-mode-and-server-mode/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 10:25:21 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Derby]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/combining-derby-embedded-mode-and-server-mode-60.htm</guid>
		<description><![CDATA[<p>Recently there have been several occasions where I have needed an application to use an embedded driver but also needed to allow for the occasional login to the database externally while the application is executing. Derby works wonderfully for this and starting a server within the application is exceedingly simple. Here I will give [...]]]></description>
			<content:encoded><![CDATA[<p>Recently there have been several occasions where I have needed an application to use an embedded driver but also needed to allow for the occasional login to the database externally while the application is executing. Derby works wonderfully for this and starting a server within the application is exceedingly simple. Here I will give just a brief example that should be enough to demonstrate the method. The code fragments here are admittedly simplistic but they work and show the principles cleanly. </p>
<pre><span style=" font-family:'Courier New,courier';"> </span></pre>
<pre><span style=" font-family:'Courier New,courier';">//First a method to get an embedded connection:</span></pre>
<pre></pre>
<pre><span style=" font-family:'Courier New,courier';">public Connection getConnection() {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">    try {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">        return DriverManager.getConnection("jdbc:derby:"+dbPath);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">    } catch (SQLException e) {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">        log.error(e.getMessage(),e);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">        return null;</span></pre>
<pre><span style=" font-family:'Courier New,courier';">    }</span></pre>
<pre><span style=" font-family:'Courier New,courier';">}</span></pre>
<pre></pre>
<pre><span style=" font-family:'Courier New,courier';">//Now a method to start the server for external connections.</span></pre>
<pre></pre>
<pre><span style=" font-family:'Courier New,courier';">private void startDBServer() {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">	try {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">		server = new NetworkServerControl(InetAddress.getByName("Localhost"),1527);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">		server.start(null);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">	} catch (Exception e) {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">		log.error(e.getMessage(),e);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">	}</span></pre>
<pre><span style=" font-family:'Courier New,courier';">}</span></pre>
<pre></pre>
<pre><span style=" font-family:'Courier New,courier';">//And lastly let's add a shudown hook to ensure the server gets a chance to exit clean.</span></pre>
<pre></pre>
<pre><span style=" font-family:'Courier New,courier';">private void setShutdownHook() {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">	Runtime.getRuntime().addShutdownHook(new Thread() {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">		public void run() {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">			log.info("**** Application ending ****");</span></pre>
<pre><span style=" font-family:'Courier New,courier';">			try {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">				server.shutdown();</span></pre>
<pre><span style=" font-family:'Courier New,courier';">				} catch (Exception e) {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">					log.error(e.getMessage(),e);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">				}</span></pre>
<pre><span style=" font-family:'Courier New,courier';">			}</span></pre>
<pre><span style=" font-family:'Courier New,courier';">    } );</span></pre>
<pre><span style=" font-family:'Courier New,courier';">}</span></pre>
<pre></pre>
<p> That&#8217;s the basics and it doesn&#8217;t get much easier.</p>
Standard disclaimer - At the time of posting I believe  all information contained to be accurate but there is absolutely no warranty or guarantee.  ]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/combining-derby-embedded-mode-and-server-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

