<?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>Kristian Lunde &#187; Java</title>
	<atom:link href="http://www.klunde.net/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.klunde.net</link>
	<description>www.klunde.net</description>
	<lastBuildDate>Wed, 01 Feb 2012 23:57:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Installing nutch 1.0 on OSX</title>
		<link>http://www.klunde.net/2009/04/07/installing-nutch-10-on-osx/</link>
		<comments>http://www.klunde.net/2009/04/07/installing-nutch-10-on-osx/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 21:15:05 +0000</pubDate>
		<dc:creator>Kristian Lunde</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[nutch]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://www.klunde.net/?p=275</guid>
		<description><![CDATA[Today I started to work on a little project that required a crawler, and Nutch seemed to do most of what I needed. The nutch team conveniently released Nutch 1.0 late in March 2009, so I had a brand new release to test out. Installing nutch 1.0 on a mac is not as straight forward [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.klunde.net%2F2009%2F04%2F07%2Finstalling-nutch-10-on-osx%2F" onclick="urchinTracker('/outgoing/api.tweetmeme.com/share?url=http_3A_2F_2Fwww.klunde.net_2F2009_2F04_2F07_2Finstalling-nutch-10-on-osx_2F&amp;referer=');"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.klunde.net%2F2009%2F04%2F07%2Finstalling-nutch-10-on-osx%2F&amp;source=kristianlunde&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Today I started to work on a little project that required a crawler, and <a href="http://lucene.apache.org/nutch/" onclick="urchinTracker('/outgoing/lucene.apache.org/nutch/?referer=');">Nutch</a> seemed to do most of what I needed. The nutch team conveniently released Nutch 1.0 late in March 2009, so I had a brand new release to test out. Installing nutch 1.0 on a mac is not as straight forward as I thought, I ran into a lot of unexpected issues and here is my cook book description of how to successfully install nutch 1.0 on your mac.</p>
<ol>
<li>Download the latest source code from the Apache SVN repository <i>http://svn.apache.org/repos/asf/lucene/nutch/</i>. I tried running it from the tarball without success, I also tried to compile the source from the tarball, but a post on the nutch forum clearly states that this will not work.</li>
<li>Set your <b>JAVA_HOME</b> and <b>NUTCH_JAVA_HOME</b> variables, again this is not straight forward, they both need to point to your real installation of Java 1.6 (earlier versions of Java will fail). I sat these variables to: <i>/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home</i>, I could not get the <i>/Library/Java/Home</i> symbolic link to work properly.</li>
<li>Compile the source code using Ant (I built it in Eclipse).</li>
<li>Setup your nutch configuration, by following the <a href="http://zillionics.com/resources/articles/NutchGuideForDummies.htm" class="broken_link" onclick="urchinTracker('/outgoing/zillionics.com/resources/articles/NutchGuideForDummies.htm?referer=');">tutorial by Peter P. Wang</a></li>
<li>Run your first crawl with: <i>./bin/nutch crawl urls -dir crawl -depth 3 -topN 50</i></li>
</ol>
<p>Most of the issues I encountered was related to the Java version and the fact that using <i>/Application/Utilities/Java/Java preferences</i> application do not really change the <b>JAVA_HOME</b> directory <i>/Library/Java/Home</i> properly. So make sure you have set both <b>JAVA_HOME</b> and <b>NUTCH_JAVA_HOME</b>, and that your OSX does not fool you when it pretend to be symbolically linking to the 1.6 installation. </p>
<p>Good luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klunde.net/2009/04/07/installing-nutch-10-on-osx/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The View Helper pattern</title>
		<link>http://www.klunde.net/2008/07/20/the-view-helper-pattern/</link>
		<comments>http://www.klunde.net/2008/07/20/the-view-helper-pattern/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 21:11:58 +0000</pubDate>
		<dc:creator>Kristian Lunde</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Reusability]]></category>
		<category><![CDATA[View Helper pattern]]></category>

		<guid isPermaLink="false">http://www.klunde.net/?p=37</guid>
		<description><![CDATA[Developing MVC (Model View Controller pattern) applications in PHP or any other language often require a lot from the view tier. The view needs to process data received from the model tier and form it into presentable data, it also has to manage user input and form that into data understandable for the model tier. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.klunde.net%2F2008%2F07%2F20%2Fthe-view-helper-pattern%2F" onclick="urchinTracker('/outgoing/api.tweetmeme.com/share?url=http_3A_2F_2Fwww.klunde.net_2F2008_2F07_2F20_2Fthe-view-helper-pattern_2F&amp;referer=');"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.klunde.net%2F2008%2F07%2F20%2Fthe-view-helper-pattern%2F&amp;source=kristianlunde&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Developing MVC (Model View Controller pattern) applications in PHP or any other language often require a lot from the view tier. The view needs to process data received from the model tier and form it into presentable data, it also has to manage user input and form that into data understandable for the model tier.<br />
This might not be a big issue while working with small application, but when it comes to midscale and large applications the view helper pattern can be of great help. The view helper pattern is one of the J2EE core patterns and the documentation can be found on: </p>
<p><a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/ViewHelper.html" onclick="urchinTracker('/outgoing/java.sun.com/blueprints/corej2eepatterns/Patterns/ViewHelper.html?referer=');">http://java.sun.com/blueprints/corej2eepatterns/Patterns/ViewHelper.html</a></p>
<p><strong>What does the helper pattern do?</strong><br />
First of all the helper pattern adds an extra tier to the system, this tier can be seen as a mid tier which has some understanding of the logic of the system, it knows a little bit about the view and a little bit about the model. Another cool thing is that the view helper pattern makes your code more reusable. When moving complex structures from the view and into a view helper it can with ease be used by other views. </p>
<p><strong>Example:</strong></p>
<p>You are writing a web application where the user writes a review of some product, the application should do auto saving of the user input every 20 second using Ajax functionality. The application should of course also save the user input then the user submits the data. The ajax request and the user submit does almost the same thing but the when the user submits the data the view should also store a rating of the product. This require the ajax request and the user submit to be two different views, or one complex view. </p>
<p>In an ordinary MVC system you would have to implement two views with very much of the similar behavior or one complex view. Using the view helper pattern you extract the storage of the user review in a helper which can be reused by both the ajax request view and the user submit view.</p>
<p>I have written a very simple implementation of the example in PHP. The implementation is not complete at all, but it is meant as a proof of concept that the reusability of code in your application can increase using the view helper pattern.</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> ProductReviewHelper</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp;* save the review</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; **/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> save<span class="br0">&#40;</span><span class="re1">$user_input</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//validate input</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re1">$input</span> <span class="sy0">=</span> <span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">validate</span><span class="br0">&#40;</span><span class="re1">$user_input</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//saves the review and return the result of the save</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re1">$review_manager</span><span class="sy0">-&gt;</span><span class="me1">save</span><span class="br0">&#40;</span><span class="re1">$input</span><span class="br0">&#91;</span><span class="st0">&#39;product_id&#39;</span><span class="br0">&#93;</span><span class="sy0">,</span> <span class="re1">$input</span><span class="br0">&#91;</span><span class="st0">&#39;review&#39;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; * validate the input </span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; **/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> validate<span class="br0">&#40;</span><span class="re1">$user_input</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re1">$filter_args</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st0">&#39;product_id&#39;</span> <span class="sy0">=&gt;</span> FILTER_VALIDATE_INT<span class="sy0">,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&#39;review&#39;</span> &nbsp; <span class="sy0">=&gt;</span> FILTER_SANITIZE_STRING<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re1">$input</span> <span class="sy0">=</span> filter_var_array<span class="br0">&#40;</span><span class="re1">$user_input</span><span class="sy0">,</span> <span class="re1">$filter_args</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//do validation</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re1">$input</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Ajax view</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$review_helper</span> <span class="sy0">=</span> <span class="kw2">new</span> ProductReviewHelper<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$result</span> <span class="sy0">=</span> <span class="re1">$review_helper</span><span class="sy0">-&gt;</span><span class="me1">save</span><span class="br0">&#40;</span><span class="re1">$_POST</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="re1">$result</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">exit</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//User submit view</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$review_helper</span> <span class="sy0">=</span> <span class="kw2">new</span> ProductReviewHelper<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$review_result</span> <span class="sy0">=</span> <span class="re1">$review_helper</span><span class="sy0">-&gt;</span><span class="me1">save</span><span class="br0">&#40;</span><span class="re1">$_POST</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$rating_helper</span> <span class="sy0">=</span> <span class="kw2">new</span> ProductRatingHelper<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$rating_result</span> <span class="sy0">=</span> <span class="re1">$rating_helper</span><span class="sy0">-&gt;</span><span class="me1">save</span><span class="br0">&#40;</span><span class="re1">$_POST</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//manage the result from the helpers</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>I am sure that the view helper pattern has helped me to write better and more organized code, which is easily understandable and very reusable.</p>
<p>If you do not use the view helper pattern, and still have solved the problem with reusability of code in the view tier please feel free to leave me a comment describing your solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klunde.net/2008/07/20/the-view-helper-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My first introduction to java and databases</title>
		<link>http://www.klunde.net/2008/05/05/my-first-introduction-to-java-and-databases/</link>
		<comments>http://www.klunde.net/2008/05/05/my-first-introduction-to-java-and-databases/#comments</comments>
		<pubDate>Mon, 05 May 2008 20:14:57 +0000</pubDate>
		<dc:creator>Kristian Lunde</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[JDBC]]></category>

		<guid isPermaLink="false">http://www.klunde.net/?p=9</guid>
		<description><![CDATA[The other day I did a complete reconfiguration of java on my system. Tonight I started to play around with java and postgresql. I installed PostgreSQL 8.2 (yes I know 8.3 is out there), and downloaded the jdbc driver for PosgreSQL. PostgreSQL After installing PostgreSQL, you have to add a user to the authorization file [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.klunde.net%2F2008%2F05%2F05%2Fmy-first-introduction-to-java-and-databases%2F" onclick="urchinTracker('/outgoing/api.tweetmeme.com/share?url=http_3A_2F_2Fwww.klunde.net_2F2008_2F05_2F05_2Fmy-first-introduction-to-java-and-databases_2F&amp;referer=');"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.klunde.net%2F2008%2F05%2F05%2Fmy-first-introduction-to-java-and-databases%2F&amp;source=kristianlunde&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>The other day I did a complete reconfiguration of java on my system. Tonight I started to play around with java and postgresql. I installed PostgreSQL 8.2 (yes I know 8.3 is out there), and downloaded the jdbc driver for PosgreSQL.</p>
<h3>PostgreSQL</h3>
<p>After installing PostgreSQL, you have to add a user to the authorization file pg_hba.conf located in /etc/postgresql/8.x/main on a ubuntu system, remember to restart the postgreSQL server after editing pg_hba.conf. When that is done add the same user to the postgreSQL server either by using postgreSQL&#8217;s <em><strong>createuser</strong></em> function or by logging into the postgreSQL server and doing a SQL CREATE USER, I did the latter one.</p>
<div class="geshi no sql">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">CREATE</span> USER kristian <span class="kw1">WITH</span> PASSWORD <span class="st0">&#39;xxxxxxxx&#39;</span> CREATEDB;</div>
</li>
</ol>
</div>
<p>This enables me to do a regular access of the database with:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">kristian<span class="sy0">@</span>Saturn:~$ psql -U kristian crawler</div>
</li>
<li class="li1">
<div class="de1">Welcome to psql <span class="nu0">8.2</span><span class="nu0">.7</span>, the PostgreSQL interactive terminal.<span class="sy0">&lt;/</span>code<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Type: &nbsp;\copyright <span class="kw1">for</span> distribution terms</div>
</li>
<li class="li1">
<div class="de1">\h <span class="kw1">for</span> <span class="kw3">help</span> with SQL commands</div>
</li>
<li class="li1">
<div class="de1">\? <span class="kw1">for</span> <span class="kw3">help</span> with psql commands</div>
</li>
<li class="li1">
<div class="de1">\g or terminate with semicolon to execute query</div>
</li>
<li class="li1">
<div class="de1">\q to quit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">crawler=</span><span class="co0">#</span></div>
</li>
</ol>
</div>
<p>My table:</p>
<div class="geshi no sql">
<ol>
<li class="li1">
<div class="de1">crawler<span class="sy0">=</span><span class="co2"># \d document;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">TABLE</span> <span class="st0">&quot;public.document&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">COLUMN</span> &nbsp; &nbsp; <span class="sy0">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Modifiers</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></div>
</li>
<li class="li1">
<div class="de1">id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sy0">|</span> integer &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">|</span> <span class="kw1">NOT</span> <span class="kw1">NULL</span> <span class="kw1">DEFAULT</span> <span class="kw1">NEXTVAL</span><span class="br0">&#40;</span><span class="st0">&#39;document_id_seq&#39;</span>::regclass<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">url &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">|</span> text &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sy0">|</span> <span class="kw1">NOT</span> <span class="kw1">NULL</span></div>
</li>
<li class="li1">
<div class="de1">document &nbsp; &nbsp; &nbsp;<span class="sy0">|</span> text &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sy0">|</span> <span class="kw1">NOT</span> <span class="kw1">NULL</span></div>
</li>
<li class="li1">
<div class="de1">ts_downloaded <span class="sy0">|</span> timestamp without time zone <span class="sy0">|</span> <span class="kw1">DEFAULT</span> now<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>Data in the table:</p>
<div class="geshi no sql">
<ol>
<li class="li1">
<div class="de1">crawler<span class="sy0">=</span><span class="co2"># select * from document;</span></div>
</li>
<li class="li1">
<div class="de1">id <span class="sy0">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sy0">|</span> document <span class="sy0">|</span> &nbsp; &nbsp; &nbsp; ts_downloaded</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></div>
</li>
<li class="li1">
<div class="de1"><span class="nu0">1</span> <span class="sy0">|</span> http://www.klunde.net <span class="sy0">|</span> jalla &nbsp; &nbsp;<span class="sy0">|</span> <span class="nu0">2008</span><span class="nu0">-04</span><span class="nu0">-19</span> <span class="nu0">21</span>:<span class="nu0">11</span>:<span class="nu0">11.805482</span></div>
</li>
</ol>
</div>
<h3>Java</h3>
<p>First thing to get the postgreSQL jdbc driver to work is to add it to the java classpath, and of course copy the actual jar file to its correct location, for instance<em> /usr/lib/jvm/java-6-sun-1.6.0.03/jre/ext/lib/</em>which is my java library path.<br />
My classpath:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">/</span>usr<span class="sy0">/</span>lib<span class="sy0">/</span>jvm<span class="sy0">/</span>java<span class="nu0">-6</span>-sun<span class="nu0">-1.6</span><span class="nu0">.0</span><span class="nu0">.03</span><span class="sy0">/</span>lib:<span class="sy0">/</span>usr<span class="sy0">/</span>lib<span class="sy0">/</span>jvm<span class="sy0">/</span>java<span class="nu0">-6</span>-sun<span class="nu0">-1.6</span><span class="nu0">.0</span><span class="nu0">.03</span><span class="sy0">/</span>jre<span class="sy0">/</span>ext<span class="sy0">/</span>lib<span class="sy0">/</span>postgresql<span class="nu0">-8.3</span><span class="nu0">-603</span>.jdbc4.jar:.</div>
</li>
</ol>
</div>
<p>Now its about time to write some actual code:</p>
<div class="geshi no java">
<ol>
<li class="li1">
<div class="de1"><span class="co2">import java.sql.Connection;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.sql.DriverManager;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.sql.PreparedStatement;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.sql.ResultSet;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.sql.SQLException;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.sql.Statement; &lt;/code&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> DatabaseTest</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">private</span> <span class="kw3">Connection</span> connection = <span class="kw2">null</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">private</span> <span class="kw2">static</span> <span class="kw2">final</span> <span class="kw3">String</span> USERNAME = <span class="st0">&quot;XXXXX&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">private</span> <span class="kw2">static</span> <span class="kw2">final</span> <span class="kw3">String</span> PASSWORD = <span class="st0">&quot;XXXXX&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">private</span> <span class="kw2">static</span> <span class="kw2">final</span> <span class="kw3">String</span> <span class="kw3">URL</span> = <span class="st0">&quot;jdbc:postgresql:&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">private</span> <span class="kw2">static</span> <span class="kw2">final</span> <span class="kw3">String</span> DATABASE = <span class="st0">&quot;crawler&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> DatabaseTest<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">try</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">connection = <span class="kw3">DriverManager</span>.<span class="me1">getConnection</span><span class="br0">&#40;</span><span class="kw3">URL</span> + DATABASE, USERNAME, PASSWORD<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">ResultSet</span> rs = doQuery<span class="br0">&#40;</span><span class="st0">&quot;SELECT * FROM document&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">rs.<span class="me1">next</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>rs.<span class="me1">getString</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">catch</span> <span class="br0">&#40;</span><span class="kw3">SQLException</span> e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;Database Exception!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">System</span>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>e.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">e.<span class="me1">printStackTrace</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw3">ResultSet</span> doQuery<span class="br0">&#40;</span><span class="kw3">String</span> sql<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">ResultSet</span> rs<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">try</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">Statement</span> stmt = connection.<span class="me1">createStatement</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">rs = stmt.<span class="me1">executeQuery</span><span class="br0">&#40;</span>sql<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">return</span> rs<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">catch</span> <span class="br0">&#40;</span><span class="kw3">SQLException</span> e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">e.<span class="me1">printStackTrace</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">return</span> <span class="kw2">null</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Trying to execute my script:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">kristian<span class="sy0">@</span>Saturn:~<span class="sy0">/</span>workspace<span class="sy0">/</span>crawler$ &nbsp;javac DatabaseTest.java</div>
</li>
<li class="li1">
<div class="de1">kristian<span class="sy0">@</span>Saturn:~<span class="sy0">/</span>workspace<span class="sy0">/</span>crawler$ &nbsp;java -Djdbc.<span class="re2">drivers=</span>org.postgresql.Driver DatabaseTest</div>
</li>
<li class="li1">
<div class="de1">http:<span class="sy0">//</span>www.klunde.net</div>
</li>
</ol>
</div>
<p>It works <img src='http://www.klunde.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  The installation and initial setup went pretty much by the book, but as a PHP developer I must say that I&#8217;m a little bit disappointed, JDBC cannot compare itself to the PHP PDO extension yet. But then again, maybe I just need to get to know the JDBC library better. Anyhow it was fun writing this little java app and refreshing some of my java skills.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klunde.net/2008/05/05/my-first-introduction-to-java-and-databases/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java on Ubuntu</title>
		<link>http://www.klunde.net/2008/05/02/java-on-ubuntu/</link>
		<comments>http://www.klunde.net/2008/05/02/java-on-ubuntu/#comments</comments>
		<pubDate>Fri, 02 May 2008 08:04:35 +0000</pubDate>
		<dc:creator>Kristian Lunde</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.klunde.net/?p=11</guid>
		<description><![CDATA[The other day I decided that it was about time to refresh my java knowledge. I&#8217;ve done some java development at work lately, but besides that It has been about 3 years since I last wrote any decent java apps. I have a few ideas of some small cool apps I want to write, but [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.klunde.net%2F2008%2F05%2F02%2Fjava-on-ubuntu%2F" onclick="urchinTracker('/outgoing/api.tweetmeme.com/share?url=http_3A_2F_2Fwww.klunde.net_2F2008_2F05_2F02_2Fjava-on-ubuntu_2F&amp;referer=');"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.klunde.net%2F2008%2F05%2F02%2Fjava-on-ubuntu%2F&amp;source=kristianlunde&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>The other day I decided that it was about time to refresh my java knowledge. I&#8217;ve done some java development at work lately, but besides that It has been about 3 years since I last wrote any decent java apps. I have a few ideas of some small cool apps I want to write, but first of all I had to check the java installation on my machine.</p>
<p>Im currently sitting on a Ubuntu 7.04 installation, so I started out by opening my console and typing<br />
<code><br />
java -version<br />
</code></p>
<p>I was a bit surprised about the result, java version could not be determined, I found out that 4 different versions of java were installed and neither the classpath or java_home were set. The java version I wished to used were not among the installed versions. I used the java installation guide on <a href="https://help.ubuntu.com/community/JavaInstallation" onclick="urchinTracker('/outgoing/help.ubuntu.com/community/JavaInstallation?referer=');">help.ubuntu.com</a> to install my preferred java version, the java 6 version from Sun. The guide was straight forward and the java installation seemed to work as expected after completing the guide.</p>
<p><code><br />
kristian@Saturn:/usr/lib$ java -version<br />
java version "1.6.0_03"<br />
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)<br />
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)<br />
</code></p>
<p>Looking good. So I tried typing:</p>
<p><code><br />
kristian@Saturn:/usr/lib$ javac -version<br />
javac: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory<br />
</code></p>
<p>Not looking that good, something was wrong <img src='http://www.klunde.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  I googled the result and found my mistake. Earlier while I was trying to get it all together with the 4 different java versions I changed the symlink in<em><strong> /usr/bin/</strong></em> and I forgot to add the <strong><em>-s</em></strong> when I created the link. Removing the symblink and recreating it did the trick.</p>
<p><code><br />
kristian@Saturn:/usr/bin$ sudo ln -s /etc/alternatives/javac javac<br />
</code></p>
<p>The javac in /etc/alternatives is a symblink to the current java version. And  trying the all famous <em><strong>javac -version</strong></em> now result in the anticipated result:</p>
<p><code><br />
kristian@Saturn:~$ javac -version<br />
javac 1.6.0_03<br />
</code></p>
<p>Now I&#8217;m all set to go and try out my java skills <img src='http://www.klunde.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.klunde.net/2008/05/02/java-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

