<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ramblings from a Bihari!</title>
	<atom:link href="http://deepakjha.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://deepakjha.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Fri, 10 Jun 2011 18:05:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='deepakjha.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ramblings from a Bihari!</title>
		<link>http://deepakjha.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://deepakjha.wordpress.com/osd.xml" title="Ramblings from a Bihari!" />
	<atom:link rel='hub' href='http://deepakjha.wordpress.com/?pushpress=hub'/>
		<item>
		<title>interesting fact about identityHashCode() method in java.lang.System Class</title>
		<link>http://deepakjha.wordpress.com/2008/07/31/interesting-fact-about-identityhashcode-method-in-javalangsystem-class/</link>
		<comments>http://deepakjha.wordpress.com/2008/07/31/interesting-fact-about-identityhashcode-method-in-javalangsystem-class/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 09:28:39 +0000</pubDate>
		<dc:creator>deepakjha</dc:creator>
				<category><![CDATA[techie stuff]]></category>

		<guid isPermaLink="false">http://deepakjha.wordpress.com/?p=17</guid>
		<description><![CDATA[The following four lines of code is provides such outputs which confused me about the identityHashCode() method of System class. System.identityHashCode() method is supposed to give the default hashcode value irrespective of whether you have overridden hascode in your class. And as we know that default implementation maps the internal memory address to an integer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=17&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The following four lines of code is provides such outputs which confused me about the identityHashCode() method of System class. System.identityHashCode() method is supposed to give the default hashcode value irrespective of whether you have overridden hascode in your class. And as we know that default implementation maps the internal memory address to an integer value.</p>
<p>1  String s = new String(new char[]{&#8216;j&#8217;, &#8216;a&#8217;,'v&#8217;,'a&#8217;});<br />
2  String s1 = new String(new char[]{&#8216;a&#8217;, &#8216;b&#8217;,'c&#8217;,'d&#8217;});</p>
<p>3  System.out.println(System.identityHashCode(s));<br />
4  System.out.println(System.identityHashCode(s1));</p>
<p>When I created a String instance by executing line 1 it would have got some memory location allocated to it. Lets say that is &#8220;x&#8221;. Then I created another instance s1 with passing some other different array to the String constructor. So s1 would have also got some memory location  allocated for it. Lets say that is &#8220;y&#8221;.</p>
<p>Now when I print the identity hash code by executing the line number 3 and 4 every time I run the program it gives me the same two integer values. And the order of values depends on the execution of line number 3 and 4 but not on 1 and 2 where actual allocation of memory happened. Thats strange for me <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/deepakjha.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/deepakjha.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deepakjha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deepakjha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deepakjha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deepakjha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deepakjha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deepakjha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deepakjha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deepakjha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deepakjha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deepakjha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deepakjha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deepakjha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deepakjha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deepakjha.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=17&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deepakjha.wordpress.com/2008/07/31/interesting-fact-about-identityhashcode-method-in-javalangsystem-class/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0fbe0297644c2944d9c1ffac06f7370?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deepakjha</media:title>
		</media:content>
	</item>
		<item>
		<title>Interesting inconsistency with java String pool</title>
		<link>http://deepakjha.wordpress.com/2008/07/31/interesting-inconsistency-with-java-string-pool/</link>
		<comments>http://deepakjha.wordpress.com/2008/07/31/interesting-inconsistency-with-java-string-pool/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 08:57:16 +0000</pubDate>
		<dc:creator>deepakjha</dc:creator>
				<category><![CDATA[techie stuff]]></category>

		<guid isPermaLink="false">http://deepakjha.wordpress.com/?p=15</guid>
		<description><![CDATA[I was just trying out the intern() method of java.lang.String class and found an interesting issue. The intern() method is supposed to put the string literal in the intern pool and give you back a handle to that. Let me explain the scenario with two programs:- public static void main(String[] args) { char[] c = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=15&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was just trying out the intern() method of java.lang.String class and found an interesting issue.</p>
<p>The intern() method is supposed to put the string literal in the intern pool and give you back a handle to that.</p>
<p>Let me explain the scenario with two programs:-</p>
<p>public static void main(String[] args) {</p>
<p>char[] c = new char[]{&#8216;a&#8217;,'b&#8217;,'c&#8217;};<br />
String s = new String(c).intern();<br />
System.out.println(System.identityHashCode(s));<br />
s = null;<br />
for (int i = 0; i &lt; 20; i++) {<br />
System.gc();<br />
}<br />
String s1 = new String(c).intern();<br />
System.out.println(System.identityHashCode(s1));</p>
<p>}</p>
<p>What are the two values this program is supposed to print ?? I think since the intern is an WeakHashMap so after the gc call it should print two different values of identityHashCode.  Yes till now we are correct theortically and practically both.  But  if you replace the character array with any of</p>
<p>1. new char[]{&#8216;a&#8217;,'b&#8217;,'c&#8217;};</p>
<p>2. new char[]{&#8216;a&#8217;,'b&#8217;};</p>
<p>3. new char[]{&#8216;a&#8217;};</p>
<p>The program will print both the hashcode values as same. Thats strange and very inconsistent. As per my understanding  the value of elements in the array should not be responsible for the behavior of intern() or any other java method.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/deepakjha.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/deepakjha.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deepakjha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deepakjha.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deepakjha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deepakjha.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deepakjha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deepakjha.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deepakjha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deepakjha.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deepakjha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deepakjha.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deepakjha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deepakjha.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deepakjha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deepakjha.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=15&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deepakjha.wordpress.com/2008/07/31/interesting-inconsistency-with-java-string-pool/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0fbe0297644c2944d9c1ffac06f7370?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deepakjha</media:title>
		</media:content>
	</item>
		<item>
		<title>did u know u can find the location of the .class file from the instance??</title>
		<link>http://deepakjha.wordpress.com/2008/04/24/did-u-know-u-can-find-the-location-of-the-class-file-from-the-instance/</link>
		<comments>http://deepakjha.wordpress.com/2008/04/24/did-u-know-u-can-find-the-location-of-the-class-file-from-the-instance/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 11:51:56 +0000</pubDate>
		<dc:creator>deepakjha</dc:creator>
				<category><![CDATA[techie stuff]]></category>

		<guid isPermaLink="false">http://deepakjha.wordpress.com/?p=12</guid>
		<description><![CDATA[In general there is no guarantee that u can always get the location(Basically URL) from where ur instance or object is loaded but luck u can&#8217;t completely discard.. The following class which i am putting tries to find out the location of teh instance from where it is loaded. All you need to do is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=12&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In general there is no guarantee that u can always get the location(Basically URL) from where ur instance or object is loaded but luck u can&#8217;t completely discard.. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The following class which i am putting tries to find out the location of teh instance from where it is loaded. All you need to do is call the getClass method on your concerned instance and pass the output to this method.</p>
<p>package com.deepak.classloader;</p>
<p>import java.io.File;<br />
import java.net.MalformedURLException;<br />
import java.net.URL;<br />
import java.security.CodeSource;<br />
import java.security.ProtectionDomain;</p>
<p>public class FindClassLoaction {</p>
<p>public static URL getClassLocation (final Class clazz)<br />
{<br />
URL clazzLocation = null;<br />
final String clazzFileName = clazz.getName().replace (&#8216;.&#8217;, &#8216;/&#8217;).concat (&#8220;.class&#8221;);</p>
<p>final ProtectionDomain pd = clazz.getProtectionDomain ();<br />
if (pd != null)<br />
{<br />
final CodeSource codeSourceOfClazz = pd.getCodeSource();<br />
if (codeSourceOfClazz != null) clazzLocation = codeSourceOfClazz.getLocation ();</p>
<p>if (clazzLocation != null)<br />
{<br />
if (&#8220;file&#8221;.equals (clazzLocation.getProtocol ()))<br />
{<br />
try<br />
{<br />
if (clazzLocation.toExternalForm ().endsWith (&#8220;.jar&#8221;) ||<br />
clazzLocation.toExternalForm ().endsWith (&#8220;.zip&#8221;))<br />
clazzLocation = new URL (&#8220;jar:&#8221;.concat (clazzLocation.toExternalForm ())<br />
.concat(&#8220;!/&#8221;).concat (clazzFileName));<br />
else if (new File (clazzLocation.getFile ()).isDirectory ())<br />
clazzLocation = new URL (clazzLocation, clazzFileName);<br />
}<br />
catch (MalformedURLException ignore) {}<br />
}<br />
}<br />
}</p>
<p>if (clazzLocation == null)<br />
{<br />
final ClassLoader clsLoader = clazz.getClassLoader ();</p>
<p>clazzLocation = clsLoader != null ?<br />
clsLoader.getResource (clazzFileName) :<br />
ClassLoader.getSystemResource (clazzFileName);<br />
}</p>
<p>return clazzLocation;<br />
}</p>
<p>}</p>
<p>The luck factor here is that u can&#8217;t guarantee the fact that every class is loaded with some ProtectionDomain i.e. It depends on the classloader whether it is creating the ProtectionDomain before loading the class&#8230;.:(</p>
<p>also the CodeSource can be null depending on the classloader implementation. U can almost be sure that protection domain and code source will be populated for the classloders which are instance of URLClassLoader. So better you can put a check on the claasloader whether its an instance of URLClassLoader to be on safe side.</p>
<p>Sun&#8217;s implementation seems to allow finding the class file as resource ..</p>
<p>enjoy&#8230;.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/deepakjha.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/deepakjha.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deepakjha.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deepakjha.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deepakjha.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deepakjha.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deepakjha.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deepakjha.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deepakjha.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deepakjha.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deepakjha.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deepakjha.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deepakjha.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deepakjha.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deepakjha.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deepakjha.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=12&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deepakjha.wordpress.com/2008/04/24/did-u-know-u-can-find-the-location-of-the-class-file-from-the-instance/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0fbe0297644c2944d9c1ffac06f7370?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deepakjha</media:title>
		</media:content>
	</item>
		<item>
		<title>Cases for Shortcomings of Single Request-Response model</title>
		<link>http://deepakjha.wordpress.com/2008/04/21/cases-for-shortcomings-of-single-request-response-model/</link>
		<comments>http://deepakjha.wordpress.com/2008/04/21/cases-for-shortcomings-of-single-request-response-model/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 05:00:35 +0000</pubDate>
		<dc:creator>deepakjha</dc:creator>
				<category><![CDATA[techie stuff]]></category>

		<guid isPermaLink="false">http://deepakjha.wordpress.com/?p=11</guid>
		<description><![CDATA[My personal experience about implementing a single request response model had been very discouraging. Consider a situation in which u want two remotely hosted instances of database to be synchronized.  The synchronization essentially means  changes at either side to be reflected  at the  other side  whenever  synchronization request  is made.  The changes here essentially means [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=11&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My personal experience about implementing a single request response model had been very discouraging. Consider a situation in which u want two remotely hosted instances of database to be synchronized.  The synchronization essentially means  changes at either side to be reflected  at the  other side  whenever  synchronization request  is made.  The changes here essentially means inserts, updates, deletes at either side and not the DDL changes to be reflected.</p>
<p>I have a solution which does this synchronization using transfer of changes at either side as XML data packets and applying the changes after successfully receiving the changed XML data packets from the other side. The solution I implemented initially was a single request response model.</p>
<p>This simply means that</p>
<p>Step 1. I will fetch the database changes at the requester side from the last stable synchronized state and convert the changes resultset to java.sql.rowset.WebRowSet kind of XML format and transfer the changes to the receiver end with the request.</p>
<p>Step 2. The receiver side will receive the changes and try to parse the XML data packets and apply the changes on the database.</p>
<p>Step 3. After committing the changes received from the requester end I will fetch the changes at the receiver end and will prepare the XML data packets out of it.</p>
<p>Step 4. The changes at the receiver end will reach and received at the requester end the same commit will happen.</p>
<p>At the end I ll have the two ends in a synchronized state.</p>
<p>The problem with this approach is that this approach is highly unreliable as it is tightly coupled with network. Any network failure will lead to again creating the synchronization request. Which is not necessary as it is always easier to cache the changes at each step(After fetching the changes, After receiving the changes at either end). Also in the single request response model I feel that acknowledgment of  a particular atomic activity   is not exchanged which will highly increase the reliability or at least we can have a save point based approach. what say ??</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/deepakjha.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/deepakjha.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deepakjha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deepakjha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deepakjha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deepakjha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deepakjha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deepakjha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deepakjha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deepakjha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deepakjha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deepakjha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deepakjha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deepakjha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deepakjha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deepakjha.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=11&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deepakjha.wordpress.com/2008/04/21/cases-for-shortcomings-of-single-request-response-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0fbe0297644c2944d9c1ffac06f7370?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deepakjha</media:title>
		</media:content>
	</item>
		<item>
		<title>Information asymmetry</title>
		<link>http://deepakjha.wordpress.com/2007/09/21/information-asymmetry/</link>
		<comments>http://deepakjha.wordpress.com/2007/09/21/information-asymmetry/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 14:06:37 +0000</pubDate>
		<dc:creator>deepakjha</dc:creator>
				<category><![CDATA[Life Around Code]]></category>

		<guid isPermaLink="false">http://deepakjha.wordpress.com/2007/09/21/information-asymmetry/</guid>
		<description><![CDATA[Once upon a time there was a village in which there lived many married couples. There were certain qualities about this village, though, that made this village unique: Whenever a man had an affair with another man&#8217;s wife, every woman in the village got to know about the affair, except his own wife. This happened [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=10&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:Arial;">Once upon a time there was a village in which there lived many married couples. There were certain qualities about this village, though, that made this village unique: </span><span style="font-family:Arial;">Whenever a man had an affair with another man&#8217;s wife, every woman in the village got to know about the affair, except his own wife. This happened because the woman who he had slept with talked about their affair with all the other women in the village, except his wife. Moreover, no one ever told his wife about the affair. </span><span style="font-family:Arial;">The strict laws of the village required that if a woman could prove that her own husband had been unfaithful towards her, then she must kill him that very day before </span><span style="font-family:Arial;">midnight</span><span style="font-family:Arial;">. Also, every woman was law-abiding, intelligent, and aware of the intelligence of other women living in that village.<br />
You and I know that exactly twenty of the men had been unfaithful to their wives. However, as no woman could prove the guilt of her husband, the village life proceeded smoothly. </span><span style="font-family:Arial;">Then, one morning, a wise old man with a long, white beard came to the village. His magical powers, and honesty was acknowledged by all and his word was taken as the gospel truth. </span><span style="font-family:Arial;">The wise old man asked all villagers to gather together in the village compound and then announced: </span><span style="font-family:Arial;">&#8220;At least one of the men in this village has been unfaithful to his wife.&#8221; </span><span style="font-family:Arial;">Questions: </span><span style="font-family:Arial;">1. What happened next? </span><span style="font-family:Arial;">2. And what this got to do with stock market crashes? </span><span style="font-family:Arial;">Answer 1: </span><span style="font-family:Arial;">After the wise old man has spoken, there shall be 19 peaceful days followed by a massive slaughter before the </span><span style="font-family:Arial;">midnight</span><span style="font-family:Arial;"> of the 20th day when twenty women will kill their husbands. </span><span style="font-family:Arial;">Proof: </span><span style="font-family:Arial;">We will use backward thinking for the proof. Indeed, the very purpose of this post is to demonstrate the utility of the backward thinking style. </span><span style="font-family:Arial;">Let&#8217;s start by assuming that there is only one unfaithful man in the village &#8211; Mr. A. Later, we shall drop this assumption. </span><span style="font-family:Arial;">Every woman in the village except Mrs. A knows that he is unfaithful. However, since no one has told her anything, and she remains blissfully ignorant. But only until the old man speaks the words, &#8220;At least one of the men in this village has been unfaithful to his wife.&#8221; </span><span style="font-family:Arial;">The old man&#8217;s words are news only for Mrs. A, and mean nothing to the other women. And because she is intelligent, she correctly reasons that if any man other than her own husband was unfaithful, she would have known about it. And since she has no such knowledge in her possession, it must mean that it&#8217;s her own husband who is unfaithful. And so, before the </span><span style="font-family:Arial;">midnight</span><span style="font-family:Arial;"> of the day the old man spoke, she must execute her husband. </span><span style="font-family:Arial;">Now, let&#8217;s assume that there were exactly two unfaithful men in the village &#8211; Mr. A and Mr. B. </span><span style="font-family:Arial;">The moment the old man speaks the words, &#8220;At least one of the men in this village has been unfaithful to his wife,&#8221; the village&#8217;s women population gets divided as follows:<br />
Every woman other than Mrs. A and Mrs. B knows the whole truth; </span><span style="font-family:Arial;">Mrs. A knows about philanderer Mr. B, but, as of now, knows nothing about  her own husband&#8217;s unfaithfulness, so she assumes that there is only one  unfaithful man &#8211; Mr. B &#8211; who will be executed by Mrs. B that night; and </span><span style="font-family:Arial;">Mrs. B knows about philanderer Mr. A, but, as of now, knows nothing about her own husband&#8217;s unfaithfulness, so she assumes that there is only one unfaithful man &#8211; Mr. A &#8211; who will be executed by Mrs. A that night.  <br />
As the </span><span style="font-family:Arial;">midnight</span><span style="font-family:Arial;"> of day one approaches, Mrs. A is expecting Mrs. B to execute her husband, and vice versa. But, and this is key, none of them do what the other one is expecting them to do! </span><span style="font-family:Arial;">The clock is ticking away and passes </span><span style="font-family:Arial;">midnight</span><span style="font-family:Arial;"> and day 2 starts. What happens now is sudden realization on the part of both Mrs. A and Mrs. B, that there must be more than one man who is unfaithful. And, since none of them had prior knowledge about this other unfaithful man, then it must be their own respective husbands who were unfaithful! </span><span style="font-family:Arial;">In other words, the inaction of one represents new information for the other. </span><span style="font-family:Arial;">Therefore, using the principles of inductive logic requiring backward thinking, both Mrs. A and Mrs. B will execute their respective husbands before the </span><span style="font-family:Arial;">midnight</span><span style="font-family:Arial;"> of day 2. </span><span style="font-family:Arial;">Now, let&#8217;s assume that there are exactly three unfaithful men in the village- Mr. A, Mr. B., and Mr. C. The same procedure can be used to show that in such a scenario, the wives of these three philandering men will kill them before the </span><span style="font-family:Arial;">midnight</span><span style="font-family:Arial;"> of day 3. </span><span style="font-family:Arial;">Using the same process, it can be shown that if exactly twenty husbands are unfaithful, their wives would finally be able to prove it on the 20th day, which will also be the day of the bloodbath. </span><span style="font-family:Arial;">Answer 2: Connection with Stock Market Crashes </span><span style="font-family:Arial;">If you replace the announcement of the old man with that provided, by say,  SEBI, the nervousness of the wives with the nervousness of the investors,  the wives&#8217; contentment as long as their own husbands weren&#8217;t cheating on  them with the investors&#8217; contentment so long as their own companies were  not indulging in fraud, the execution of twenty husbands with massive  dumping of stocks, and the time lag between the old man&#8217;s announcement and  the killings with the time lag between the old man&#8217;s announcement and the  market crash, the connection between the story and market crashes becomes  obvious. </span><strong><span style="font-family:Arial;">Information Asymmetry </span></strong><span style="font-family:Arial;">One of the most interesting aspects about the story is the role of information asymmetry. </span><span style="font-family:Arial;">You and I knew that there were exactly twenty unfaithful men in the village. We had complete information about the number of unfaithful men in that village but not their identity. </span><span style="font-family:Arial;">On the other hand, every woman in the village knew the identity of at least nineteen unfaithful men. For example, if you were Mrs. A, you would have known about nineteen unfaithful men, but not about your own husband&#8217;s unfaithfulness. And, if you were one of the women whose husband was faithful, then you&#8217;d know the identity of twenty unfaithful men. </span><span style="font-family:Arial;">But the old man did not say that there were twenty unfaithful men in the village. All he said was that there was at least one unfaithful man in the village. So, his statement, did not add anything to the knowledge of any individual woman because each of them knew of at least nineteen unfaithful men! </span><span style="font-family:Arial;">And yet, his statement caused the bloodbath after twenty days! </span><span style="font-family:Arial;">The lesson is simple: It&#8217;s not necessary for any new information to cause havoc in the stock market. Sudden realizations about the stupidity of  gross overvaluations and dubious accounting practices followed by some  companies in bubble markets can and do occur simultaneously in the minds  of the crowd. And that sudden realization can cause markets to crash! </span><font face="Times New Roman"> </font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/deepakjha.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/deepakjha.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deepakjha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deepakjha.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deepakjha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deepakjha.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deepakjha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deepakjha.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deepakjha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deepakjha.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deepakjha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deepakjha.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deepakjha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deepakjha.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deepakjha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deepakjha.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=10&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deepakjha.wordpress.com/2007/09/21/information-asymmetry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0fbe0297644c2944d9c1ffac06f7370?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deepakjha</media:title>
		</media:content>
	</item>
		<item>
		<title>Another bad mark on My Image in Boss&#8217;s Mind&#8230;&#8230;:(</title>
		<link>http://deepakjha.wordpress.com/2007/09/21/another-bad-mark-on-my-image-in-bosss-mind/</link>
		<comments>http://deepakjha.wordpress.com/2007/09/21/another-bad-mark-on-my-image-in-bosss-mind/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 05:22:16 +0000</pubDate>
		<dc:creator>deepakjha</dc:creator>
				<category><![CDATA[Life Around Code]]></category>

		<guid isPermaLink="false">http://deepakjha.wordpress.com/2007/09/21/another-bad-mark-on-my-image-in-bosss-mind/</guid>
		<description><![CDATA[Another bad incident&#8230;&#8230; For the whole fraternity of indian cricket fans the 6 sixes on Yuvi against Broad is like immaculate piece of gift. But for me it went into another embarrasing laps of working day&#8230;. After the six sixes me and my lovely brothers got highly spirited for india and bought the same spirit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=9&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Another bad incident&#8230;&#8230;</p>
<p>For the whole fraternity of indian cricket fans the 6 sixes on Yuvi against Broad is like immaculate piece of gift. But for me it went into another embarrasing laps of working day&#8230;.</p>
<p>After the six sixes me and my lovely brothers got highly spirited for india  and bought the same spirit we are having since our college days&#8230;&#8230; IMPERIAL BLUE with Thumps UP(SHhhhhh&#8230; my boss can forgive me for not coming to office but he will throw me out of office if he found me mixing cold drink with Whysky) &#8230;</p>
<p>Anyways by the end of the match i was  full bottle down and not in my senses. They told me that i slept after 4 in the morning and i dont know what happened after that. But when i woke up next morning it was 5 Pm in the evening&#8230; High hangover&#8230;. Shittttt. Again not in the state of going enywhere&#8230; i know my this habit will some day take my job from me &#8230;&#8230;. God save me from the scoldings of &#8230;&#8230;&#8230;.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/deepakjha.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/deepakjha.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deepakjha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deepakjha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deepakjha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deepakjha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deepakjha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deepakjha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deepakjha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deepakjha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deepakjha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deepakjha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deepakjha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deepakjha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deepakjha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deepakjha.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=9&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deepakjha.wordpress.com/2007/09/21/another-bad-mark-on-my-image-in-bosss-mind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0fbe0297644c2944d9c1ffac06f7370?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deepakjha</media:title>
		</media:content>
	</item>
		<item>
		<title>Sharing the same connection or transaction space between derby sql and java.</title>
		<link>http://deepakjha.wordpress.com/2007/09/21/sharing-the-same-connection-or-transaction-space-between-derby-sql-and-java/</link>
		<comments>http://deepakjha.wordpress.com/2007/09/21/sharing-the-same-connection-or-transaction-space-between-derby-sql-and-java/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 05:06:35 +0000</pubDate>
		<dc:creator>deepakjha</dc:creator>
				<category><![CDATA[techie stuff]]></category>

		<guid isPermaLink="false">http://deepakjha.wordpress.com/2007/09/21/sharing-the-same-connection-or-transaction-space-between-derby-sql-and-java/</guid>
		<description><![CDATA[Think of a situation in which you want to write a stored procedure in Derby and the procedure is calling a static java method inside the same JVM. The important requirement here is that the java method is is being executed by the SQL stored procedure is modifiying some data in the database. So finally [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=8&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Think of a situation in which you want to write a stored procedure in Derby and the procedure is calling a static java method inside the same JVM. The important requirement here is that the java method is is being executed by the SQL stored procedure is modifiying some data in the database. So finally the scenario is :: SQL is modifying the data as well as the java method is also modifying the data in the same database. So one must be thinking of transaction safety&#8230;. e.g when u rollback both the changes(made by SQL and the corresponding java method) must get rollback. Following is the example&#8230;&#8230;.</p>
<p>Trigger which calls a stored procedure.:::::</p>
<p>CREATE TRIGGER COMPOSITE_U_T AFTER UPDATE ON COMPOSITE REFERENCING NEW AS NEWROW FOR EACH ROW MODE DB2SQL CALL PRO_TRIGGER(&#8216;ID1&#8242;, &#8216;ID2&#8242;, NEWROW.ID1, NEWROW.ID2, &#8216;COMPOSITE&#8217;, &#8216;U&#8217;);</p>
<p>Procedure which is called by trigger and which in turn calls the static java method::::</p>
<p>CREATE PROCEDURE PRO_TRIGGER(P_K_1 VARCHAR(50), P_K_2 VARCHAR(50), PK_VAL1 INTEGER, PK_VAL2 INTEGER, TABLE_NAME VARCHAR(100), FLAG VARCHAR(2)) PARAMETER STYLE JAVA MODIFIES SQL DATA LANGUAGE JAVA EXTERNAL NAME &#8216;com.pramati.bfly.sync.util.db.TriggerClass.executeTriggerLogic&#8217;;</p>
<p>The java method which shares the same transaction space as the Procedure which is calling it.</p>
<p><strong><font size="2" color="#7f0055">public</font></strong><font size="2"> </font><strong><font size="2" color="#7f0055">static</font></strong><font size="2"> </font><strong><font size="2" color="#7f0055">void</font></strong><font size="2"> executeTriggerLogic(String pKColName1,</font><font size="2">String pKColName2, </font><strong><font size="2" color="#7f0055">int</font></strong><font size="2"> pKValue1, </font><strong><font size="2" color="#7f0055">int</font></strong><font size="2"> pKValue2, String tableName,</font><font size="2"></p>
<p align="left">String flag) {</p>
<p align="left">String updateDashTableQry = <font size="2" color="#2a00ff">&#8220;update &#8220;</font></p>
<p></font><font size="2"></p>
<p align="left">+ tableName</p>
<p align="left">+ <font size="2" color="#2a00ff">&#8220;_dash set time = current_timestamp, flag = &#8216;&#8221;</font></p>
<p></font><font size="2"></p>
<p align="left">+ flag</p>
<p align="left">+ <font size="2" color="#2a00ff">&#8220;&#8216;, user_id = &#8216;error&#8217; &#8220;</font></p>
<p></font><font size="2"></p>
<p align="left">+ (flag.equalsIgnoreCase(<font size="2" color="#2a00ff">&#8220;I&#8221;</font><font size="2">) ? </font><font size="2" color="#2a00ff">&#8220;, inserted_time = current_timestamp&#8221;</font></p>
<p></font><font size="2">: </font><font size="2" color="#2a00ff">&#8220;&#8221;</font><font size="2">) + </font><font size="2" color="#2a00ff">&#8221; where &#8220;</font><font size="2"> + pKColName1 + </font><font size="2" color="#2a00ff">&#8221; = &#8220;</font><font size="2"> + pKValue1</font><font size="2"></p>
<p align="left">+ <font size="2" color="#2a00ff">&#8221; AND &#8220;</font><font size="2"> + pKColName2 + </font><font size="2" color="#2a00ff">&#8221; = &#8220;</font><font size="2"> + pKValue2;String insertIntoDashTableQry = </font></p>
<p></font><font size="2" color="#2a00ff">&#8220;insert into &#8220;</font><font size="2"> + tableName</font><font size="2"> + <font size="2" color="#2a00ff">&#8220;_dash values( &#8220;</font><font size="2"> + pKValue1 + </font><font size="2" color="#2a00ff">&#8220;, &#8220;</font><font size="2"> + pKValue2</font></font><font size="2"><font size="2"></p>
<p align="left">+ <font size="2" color="#2a00ff">&#8220;, current_timestamp, &#8216;&#8221;</font><font size="2"> + flag + </font><font size="2" color="#2a00ff">&#8220;&#8216;, &#8220;</font></p>
<p></font></font><font size="2">+ (flag.equalsIgnoreCase(</font><font size="2" color="#2a00ff">&#8220;I&#8221;</font><font size="2">) ? </font><font size="2" color="#2a00ff">&#8220;current_timestamp&#8221;</font><font size="2"> : </font><strong><font size="2" color="#7f0055">null</font></strong><font size="2">)</font><font size="2"></p>
<p align="left">+ <font size="2" color="#2a00ff">&#8220;, &#8216;error&#8217;)&#8221;</font><font size="2">;</font></p>
<p></font><strong><font size="2" color="#7f0055">try</font></strong><font size="2"> {</font><font size="2"></p>
<p align="left">Connection conn = DriverManager</p>
<p>.<em>getConnection</em>(</font><font size="2" color="#2a00ff">&#8220;jdbc:default:connection&#8221;</font><font size="2">);</font><font size="2"></p>
<p align="left">String query = <font size="2" color="#2a00ff">&#8220;select count(*) from &#8220;</font><font size="2"> + tableName + </font><font size="2" color="#2a00ff">&#8220;_dash where &#8220;</font></p>
<p></font><font size="2">+ pKColName1 + </font><font size="2" color="#2a00ff">&#8221; = &#8220;</font><font size="2"> + pKValue1 + </font><font size="2" color="#2a00ff">&#8221; AND &#8220;</font><font size="2"> + pKColName2</font><font size="2"></p>
<p align="left">+ <font size="2" color="#2a00ff">&#8221; = &#8220;</font><font size="2"> + pKValue2;</font></p>
<p></font><strong><font size="2" color="#7f0055">int</font></strong><font size="2"> count = 1;</font><font size="2"></p>
<p align="left">PreparedStatement ps = conn.prepareStatement(query);</p>
<p align="left">ResultSet rs = ps.executeQuery();</p>
<p></font><strong><font size="2" color="#7f0055">if</font></strong><font size="2"> (rs.next()) {</font><font size="2"></p>
<p align="left">count = rs.getInt(1);</p>
<p align="left">}</p>
<p></font><strong><font size="2" color="#7f0055">if</font></strong><font size="2"> (count &gt; 0) {</font><font size="2">System.</font><em><font size="2" color="#0000c0">out</font></em><font size="2">.println(</font><font size="2" color="#2a00ff">&#8220;update query ::&#8221;</font><font size="2"> + updateDashTableQry);</font><font size="2"></p>
<p align="left">PreparedStatement ps1 = conn</p>
<p align="left">.prepareStatement(updateDashTableQry);</p>
<p align="left">ps1.executeUpdate();</p>
<p>} </font><strong><font size="2" color="#7f0055">else</font></strong><font size="2"> {</font><font size="2">System.</font><em><font size="2" color="#0000c0">out</font></em><font size="2">.println(</font><font size="2" color="#2a00ff">&#8220;insert query ::&#8221;</font><font size="2"> + insertIntoDashTableQry);</font><font size="2"></p>
<p align="left">PreparedStatement ps2 = conn</p>
<p align="left">.prepareStatement(insertIntoDashTableQry);</p>
<p align="left">ps2.executeUpdate();</p>
<p align="left">}</p>
<p align="left">conn.close();</p>
<p>} </font><strong><font size="2" color="#7f0055">catch</font></strong><font size="2"> (SQLException e) {</font><font size="2"></p>
<p align="left">e.printStackTrace();</p>
<p align="left">}</p>
<p align="left">&nbsp;</p>
<p>}</p>
<p>The most important line as per sharing the same transaction space or sharing the same connection instance between the procedure and the static java method is</p>
<p></font></p>
<p align="left">Connection conn = DriverManager</p>
<p align="left">.<em>getConnection</em>(<font size="2" color="#2a00ff">&#8220;jdbc:default:connection&#8221;</font><font size="2">);</font></p>
<p align="left"><font size="2">You even dont need to load the Driver as in normal JDBC routine. The above is a very good example which can solve a major migration issue from a Oracle  database trigger to the Java Database(derby) trigger.</font></p>
<p align="left">&nbsp;</p>
<p align="left"><font size="2">Cheers!!!!</font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/deepakjha.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/deepakjha.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deepakjha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deepakjha.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deepakjha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deepakjha.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deepakjha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deepakjha.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deepakjha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deepakjha.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deepakjha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deepakjha.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deepakjha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deepakjha.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deepakjha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deepakjha.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=8&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deepakjha.wordpress.com/2007/09/21/sharing-the-same-connection-or-transaction-space-between-derby-sql-and-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0fbe0297644c2944d9c1ffac06f7370?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deepakjha</media:title>
		</media:content>
	</item>
		<item>
		<title>Did u know that u can shutdown someone&#8217;s machine(windows) using java????</title>
		<link>http://deepakjha.wordpress.com/2007/09/17/did-u-know-that-u-can-shutdown-someones-machinewindows-using-java/</link>
		<comments>http://deepakjha.wordpress.com/2007/09/17/did-u-know-that-u-can-shutdown-someones-machinewindows-using-java/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 11:14:25 +0000</pubDate>
		<dc:creator>deepakjha</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[techie stuff]]></category>

		<guid isPermaLink="false">http://deepakjha.wordpress.com/2007/09/17/did-u-know-that-u-can-shutdown-someones-machinewindows-using-java/</guid>
		<description><![CDATA[ha ha ha, there is no particular fundoo java is involved here. Here is the code&#8230;u must know the location where windows is installed. Currently i assumed it to be&#8230;.C:\Windows. So, the cmd.exe is inside C:\Windows\System32. Now follows the code&#8230;. package com.deepak.entertainment; import java.io.IOException; import java.io.OutputStream; public class Deepak {    public static void main(String[] [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=7&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ha ha ha, there is no particular fundoo java is involved here. Here is the code&#8230;u must know the location where windows is installed. Currently i assumed it to be&#8230;.C:\Windows. So, the cmd.exe is inside C:\Windows\System32. Now follows the code&#8230;.</p>
<p>package com.deepak.entertainment;</p>
<p>import java.io.IOException;<br />
import java.io.OutputStream;</p>
<p>public class Deepak {<br />
 <br />
 public static void main(String[] args) throws InterruptedException {<br />
  Runtime runtime = Runtime.getRuntime();<br />
  try {<br />
   Process process = runtime.exec(&#8220;C:\\WINDOWS\\system32\\cmd.exe&#8221;);<br />
   OutputStream os = process.getOutputStream();<br />
   os.write(&#8220;shutdown -s -f -t 90 \n\r&#8221;.getBytes());<br />
   os.close();<br />
   process.waitFor();<br />
  } catch (IOException e) {<br />
   e.printStackTrace();<br />
  }<br />
 }</p>
<p>}</p>
<p>package this class in a jar file with proper Main-Class entry in manifest file. U can always use jar -mcvf command to create a jar file if u have a proper manifest file. Otherwise the IDEs like eclipse allow tou to export ur main class as a jar file. Done!!!</p>
<p>Now, give this jar file a good name something like &#8220;titanic.jar&#8221; or something and send it to ur friends. If they have a jdk instlled and they double click the file(open with java) the machine will be shutdown in 90 seconds(configurable in the above code). You cant kill the shutdown process untill you open a command prompt and type</p>
<p>shutdown -a</p>
<p>a is for aborting shutdown.</p>
<p>Cheersssssssssssss!!!!!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/deepakjha.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/deepakjha.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deepakjha.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deepakjha.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deepakjha.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deepakjha.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deepakjha.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deepakjha.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deepakjha.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deepakjha.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deepakjha.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deepakjha.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deepakjha.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deepakjha.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deepakjha.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deepakjha.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=7&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deepakjha.wordpress.com/2007/09/17/did-u-know-that-u-can-shutdown-someones-machinewindows-using-java/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0fbe0297644c2944d9c1ffac06f7370?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deepakjha</media:title>
		</media:content>
	</item>
		<item>
		<title>Utilizing JAVA&#8217;s power in Derby Database Triggers</title>
		<link>http://deepakjha.wordpress.com/2007/09/17/utilizing-javas-power-in-derby-database-triggers/</link>
		<comments>http://deepakjha.wordpress.com/2007/09/17/utilizing-javas-power-in-derby-database-triggers/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 10:38:55 +0000</pubDate>
		<dc:creator>deepakjha</dc:creator>
				<category><![CDATA[techie stuff]]></category>

		<guid isPermaLink="false">http://deepakjha.wordpress.com/2007/09/17/utilizing-javas-power-in-derby-database-triggers/</guid>
		<description><![CDATA[In oracle we know that we can do a hell lot of things inside a trigger which is database specific. For example, just consider the following trigger statement&#8230;. create or replace trigger &#60;table_name&#62;_u_t after update on &#60;table_name&#62; referencing new as newRow for each row declare counts integer:=0; begin select count(*) into counts from &#60;table_name&#62;_dash where  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=6&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In oracle we know that we can do a hell lot of things inside a trigger which is database specific. For example, just consider the following trigger statement&#8230;.</p>
<p>create or replace trigger &lt;table_name&gt;_u_t after update on &lt;table_name&gt;</p>
<p>referencing new as newRow</p>
<p>for each row</p>
<p>declare counts integer:=0;</p>
<p>begin</p>
<p>select count(*) into counts from &lt;table_name&gt;_dash where  primary_key_column_name = :newRow.primary_key_column_name  ;</p>
<p>if(counts &gt; 0) then update &lt;table_name&gt;_dash set time = sysdate, flag = &#8216;U&#8217;, user_id = &#8216;error&#8217; where  primary_key_column_name = :newRow.primary_key_column_name  ;</p>
<p>else</p>
<p>insert into &lt;table_name&gt;_dash values( :newRow.primary_key_column_name, sysdate, &#8216;U&#8217;, null, &#8216;error&#8217;); end if;</p>
<p>end;</p>
<p>You can see that almost a procedure is executed inside the trigger statement after update on the table. But these things u can&#8217;t do in derby database. Also, it is not that readable code. So here comes using the power of java and getting the above functionality of the trigger in derby database&#8230;..</p>
<p>1. First u need to write a method which u want to execute when some update is happening on table.</p>
<p><strong></strong><strong><font size="2" color="#7f0055">package<font size="2"> com.deepak.test;</font><font size="2"></p>
<p align="left">&nbsp;</p>
<p></font></font></strong><strong></strong><strong><font size="2" color="#7f0055"></p>
<p align="left">import<font size="2"> java.sql.Connection;</font></p>
<p></font></strong><strong></strong><strong><font size="2" color="#7f0055"></p>
<p align="left">import<font size="2"> java.sql.DriverManager;</font></p>
<p></font></strong><strong></strong><strong><font size="2" color="#7f0055"></p>
<p align="left">import<font size="2"> java.sql.PreparedStatement;</font></p>
<p></font></strong><strong></strong><strong><font size="2" color="#7f0055"></p>
<p align="left">import<font size="2"> java.sql.ResultSet;</font></p>
<p></font></strong><strong><font size="2" color="#7f0055">import</font></strong><font size="2"> java.sql.SQLException;</font><font size="2"></p>
<p align="left">&nbsp;</p>
<p></font><strong><font size="2" color="#7f0055">public</font></strong><font size="2"> </font><strong><font size="2" color="#7f0055">class</font></strong><font size="2"> TriggerClass {</font><font size="2"></p>
<p align="left">&nbsp;</p>
<p></font><strong><font size="2" color="#7f0055">public</font></strong><font size="2"> </font><strong><font size="2" color="#7f0055">static</font></strong><font size="2"> </font><strong><font size="2" color="#7f0055">int</font></strong><font size="2"> createTrigger(String primaryKeyColumnName,</font><font size="2"> <strong><font size="2" color="#7f0055">int</font></strong><font size="2"> primaryKeyValue, String tableName, String flag) {</font><font size="2"></p>
<p align="left">String updateDashTableQry = <font size="2" color="#2a00ff">&#8220;update &#8220;</font></p>
<p></font></font><font size="2"></p>
<p align="left">+ tableName</p>
<p align="left">+ <font size="2" color="#2a00ff">&#8220;_dash set time = current_timestamp, flag = &#8216;&#8221;</font></p>
<p></font><font size="2"></p>
<p align="left">+ flag</p>
<p align="left">+ <font size="2" color="#2a00ff">&#8220;&#8216;, user_id = &#8216;error&#8217; &#8220;</font></p>
<p></font><font size="2"></p>
<p align="left">+ (flag.equalsIgnoreCase(<font size="2" color="#2a00ff">&#8220;I&#8221;</font><font size="2">) ? </font><font size="2" color="#2a00ff">&#8220;, inserted_time = current_timestamp&#8221;</font></p>
<p></font><font size="2"></p>
<p align="left">: <font size="2" color="#2a00ff">&#8220;&#8221;</font><font size="2">) + </font><font size="2" color="#2a00ff">&#8221; where &#8220;</font><font size="2"> + primaryKeyColumnName + </font><font size="2" color="#2a00ff">&#8221; = &#8220;</font></p>
<p></font><font size="2"></p>
<p align="left">+ primaryKeyValue;</p>
<p>String insertIntoDashTableQry = </font><font size="2" color="#2a00ff">&#8220;insert into &#8220;</font><font size="2"> + tableName</font><font size="2"></p>
<p align="left">+ <font size="2" color="#2a00ff">&#8220;_dash values( &#8220;</font><font size="2"> + primaryKeyValue + </font><font size="2" color="#2a00ff">&#8220;, current_timestamp, &#8216;&#8221;</font></p>
<p></font><font size="2"></p>
<p align="left">+ flag + <font size="2" color="#2a00ff">&#8220;&#8216;, &#8220;</font></p>
<p></font><font size="2">+ (flag.equalsIgnoreCase(</font><font size="2" color="#2a00ff">&#8220;I&#8221;</font><font size="2">) ? </font><font size="2" color="#2a00ff">&#8220;current_timestamp&#8221;</font><font size="2"> : </font><strong><font size="2" color="#7f0055">null</font></strong><font size="2">)</font><font size="2"></p>
<p align="left">+ <font size="2" color="#2a00ff">&#8220;, &#8216;error&#8217;)&#8221;</font><font size="2">;System.</font></p>
<p></font><em><font size="2" color="#0000c0">out</font></em><font size="2">.println(</font><font size="2" color="#2a00ff">&#8220;update query ::&#8221;</font><font size="2"> + updateDashTableQry);</font><font size="2"></p>
<p align="left"><strong><font size="2" color="#7f0055">try</font></strong><font size="2"> {Class.<em>forName</em>(</font></p>
<p></font><font size="2" color="#2a00ff">&#8220;org.apache.derby.jdbc.EmbeddedDriver&#8221;</font><font size="2">);</font><font size="2"></p>
<p align="left">Connection conn = DriverManager</p>
<p>.<em>getConnection</em>(</font><font size="2" color="#2a00ff">&#8220;jdbc:derby:deepakdb&#8221;</font><font size="2">);</font><font size="2"></p>
<p align="left">String query = <font size="2" color="#2a00ff">&#8220;select count(*) from &#8220;</font><font size="2"> + tableName + </font><font size="2" color="#2a00ff">&#8220;_dash where &#8220;</font></p>
<p></font><font size="2">+ primaryKeyColumnName + </font><font size="2" color="#2a00ff">&#8221; = &#8220;</font><font size="2"> + primaryKeyValue;</font><strong><font size="2" color="#7f0055">int</font></strong><font size="2"> count = 0;</font><font size="2"></p>
<p align="left">PreparedStatement ps = conn.prepareStatement(query);</p>
<p align="left">ResultSet rs = ps.executeQuery();</p>
<p></font><strong><font size="2" color="#7f0055">if</font></strong><font size="2"> (rs.next()) {</font><font size="2"></p>
<p align="left">count = rs.getInt(1);</p>
<p align="left">}</p>
<p></font><strong><font size="2" color="#7f0055">if</font></strong><font size="2"> (count &gt; 0) {</font><font size="2"></p>
<p align="left">PreparedStatement ps1 = conn</p>
<p align="left">.prepareStatement(updateDashTableQry);</p>
<p align="left">ps1.executeUpdate();</p>
<p>} </font><strong><font size="2" color="#7f0055">else</font></strong><font size="2"> {</font><font size="2"></p>
<p align="left">PreparedStatement ps2 = conn</p>
<p align="left">.prepareStatement(insertIntoDashTableQry);</p>
<p align="left">ps2.executeUpdate();</p>
<p align="left">}</p>
<p align="left">conn.close();</p>
<p>} </font><strong><font size="2" color="#7f0055">catch</font></strong><font size="2"> (ClassNotFoundException e) {</font><font size="2"></p>
<p align="left">e.printStackTrace();</p>
<p>} </font><strong><font size="2" color="#7f0055">catch</font></strong><font size="2"> (SQLException e) {</font><font size="2"></p>
<p align="left">e.printStackTrace();</p>
<p align="left">}</p>
<p align="left">&nbsp;</p>
<p></font><strong><font size="2" color="#7f0055">return</font></strong><font size="2"> 1;</font><font size="2"></p>
<p align="left">}</p>
<p align="left">&nbsp;</p>
<p>}</p>
<p>2. Now u need to create a Function or procedure which will call this createTrigger method written above.</p>
<p>CREATE FUNCTION FUNC_TRIGGER(PK_COLUMN_NAME VARCHAR(50), PK_COLUMN_VALUE INT, TABLE_NAME VARCHAR(50), FLAG VARCHAR(2)) RETURNS INT LANGUAGE JAVA PARAMETER STYLE JAVA NO SQL EXTERNAL NAME &#8216;com.deepak.test.TriggerClass.createTrigger&#8217;;</p>
<p>3. And finally you can call this database function created above in a trigger like the following code snippet.</p>
<p>create trigger &lt;TABLE_NAME&gt;_u_t after update on &lt;TABLE_NAME&gt;</p>
<p> referencing new as newRow </p>
<p>for each row</p>
<p>MODE DB2SQL</p>
<p>SELECT FUNC_TRIGGER(&#8216;ID&#8217;, newRow.ID, &#8216;TEST_TRIGGER&#8217;, &#8216;U&#8217;) from sysibm.sysdummy1; </p>
<p>I have used sysibm.sysdummy1 because i dint want to pass any of the table data inside the function.</p>
<p></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/deepakjha.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/deepakjha.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deepakjha.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deepakjha.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deepakjha.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deepakjha.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deepakjha.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deepakjha.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deepakjha.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deepakjha.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deepakjha.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deepakjha.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deepakjha.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deepakjha.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deepakjha.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deepakjha.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=6&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deepakjha.wordpress.com/2007/09/17/utilizing-javas-power-in-derby-database-triggers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0fbe0297644c2944d9c1ffac06f7370?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deepakjha</media:title>
		</media:content>
	</item>
		<item>
		<title>Dids u know that u can search across multiple columns in a database table??</title>
		<link>http://deepakjha.wordpress.com/2007/08/31/do-u-know-how-to-compare-full-text-in-database/</link>
		<comments>http://deepakjha.wordpress.com/2007/08/31/do-u-know-how-to-compare-full-text-in-database/#comments</comments>
		<pubDate>Fri, 31 Aug 2007 11:55:23 +0000</pubDate>
		<dc:creator>deepakjha</dc:creator>
				<category><![CDATA[techie stuff]]></category>

		<guid isPermaLink="false">http://deepakjha.wordpress.com/2007/08/31/do-u-know-how-to-compare-full-text-in-database/</guid>
		<description><![CDATA[Problem :- There are three columns in a table on MySQL database. Table Name :- Files Column Names :- Title, Tags, Description Lets Say that the search term is &#8220;red apple fresh&#8221;. Here is the current wrong query which tries to search this term: SELECT * FROM files WHERE (files.title LIKE &#8216;%&#8221;red apple fresh&#8221;%&#8217; OR files.tags [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=5&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Problem :- There are three columns in a table on MySQL database.</p>
<p>Table Name :- Files</p>
<p>Column Names :- Title, Tags, Description</p>
<p>Lets Say that the search term is &#8220;red apple fresh&#8221;.</p>
<p>Here is the current wrong query which tries to search this term:</p>
<p>SELECT * FROM files WHERE (files.title LIKE &#8216;%&#8221;red apple fresh&#8221;%&#8217; OR files.tags LIKE &#8216;%red apple fresh&#8221;%&#8217; OR files.description LIKE &#8216;%red apple fresh&#8221;%&#8217;) ;</p>
<p>The problem with this query is  that it will only select items from the database that have &#8220;red apple fresh&#8221; together as one term in either the title, tags or description fields. Also if the term &#8220;fresh apple red&#8221; rather than &#8220;red apple fresh&#8221; is in either of the fields it will not select the item from the database.</p>
<p>So i needed a query that could select the item if the word &#8220;red&#8221; is in one field and &#8220;apple&#8221; is in another field and &#8220;fresh&#8221; is in the  third field. Also the search should be order insensitive. A one word search like &#8220;apple&#8221; should result in fetching any item with that word in any of these three fields.</p>
<p>Also with the current query if the person searches &#8220;red&#8221; then the results will show irrelevant items such as items with anything starting with &#8220;red&#8230;&#8221; such as &#8220;reddish&#8221; &#8220;reddy&#8221; ect. This is another error I&#8217;s trying to overcome.</p>
<p>Solution:-</p>
<p>Steps of the solution of the above pages is as follows:-</p>
<p>1. The storage engine of the above table should be MyISAM for the coming query to work. So we need to fire the following query to change the Storage engine of the table.</p>
<p>Alter table Files ENGINE=MyISAM;</p>
<p>2. Also the FULLTEXT search shall be enabled where the FULLTEXT is constituting all the three columns where the search term is supposed to occur.</p>
<p>Alter table files add FULLTEXT(title, tags, description);</p>
<p>3. Now the following query will solve the above problem.</p>
<p>query = Select * from files where (match(files, tags, description) Against (&#8216;+red+apple+fresh&#8217;);</p>
<p>Cheers!!!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/deepakjha.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/deepakjha.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deepakjha.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deepakjha.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deepakjha.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deepakjha.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deepakjha.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deepakjha.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deepakjha.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deepakjha.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deepakjha.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deepakjha.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deepakjha.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deepakjha.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deepakjha.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deepakjha.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deepakjha.wordpress.com&amp;blog=1142183&amp;post=5&amp;subd=deepakjha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deepakjha.wordpress.com/2007/08/31/do-u-know-how-to-compare-full-text-in-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0fbe0297644c2944d9c1ffac06f7370?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deepakjha</media:title>
		</media:content>
	</item>
	</channel>
</rss>
