<?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>Kruders.com</title>
	<atom:link href="http://kruders.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kruders.com</link>
	<description>Coding is Poetry</description>
	<lastBuildDate>Mon, 08 Apr 2013 05:04:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>How to change Java Version in Linux?</title>
		<link>http://kruders.com/linux/how-to-change-java-version-in-linux/</link>
		<comments>http://kruders.com/linux/how-to-change-java-version-in-linux/#comments</comments>
		<pubDate>Fri, 22 Mar 2013 03:21:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://kruders.com/?p=3322</guid>
		<description><![CDATA[In this article, you will see how to change default java version to latest version.Check the current version used on your system. [root@localhost /]# java -version Example Output java version &#8220;1.4.2&#8243;gij (GNU libgc) version 4.1.2 2008704 (Red Hat 1.4.2-48) If there are multiple versions of java, you can change the default version by executing following [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size: 14px;">
<p style="font-size: 14px; text-align: justify;">In this article, you will see how to change default java version to latest version.<br/><br/>Check the current version used on your system.</p>
<div class="linux-highlight"><span style="font-size: 13px;">[root@localhost /]# java -version<br />
</span></div>
<p><span style="font-size: 13px; color: #FF7200;"><b>Example Output</b></span></p>
<div class="linux-highlight"><span style="font-size: 13px;">java version &#8220;1.4.2&#8243;<br/>gij (GNU libgc) version 4.1.2 2008704 (Red Hat 1.4.2-48)</span></div>
<p><span style="font-size: 13px;">If there are multiple versions of java, you can change the default version by executing following command. It will also display which is default version used by your machine (indicated by *).</span></p>
<div class="linux-highlight"><span style="font-size: 13px;">[root@localhost /]#update-alternatives &#8211;config java</span></div>
<p><span style="font-size: 13px; color: #FF7200;"><b>Example Output</b></span></p>
<div class="linux-highlight"><span style="font-size: 13px;">[root@localhost /]#update-alternatives &#8211;config java<br/><br/>There are 2 programs which provide &#8216;java&#8217;.<br/><br/>   Selection       Command<br/><br/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br/>  *+ 1              /usr/java/jdk1.4.2/jre/bin/java<br/>     2              /usr/lib/jvm/jre-1.7.0.-openjdk.x86_64/bin/java<br/><br/>Enter to keep the current selection[+], or type selection number : 2</span></div>
<p style="font-size: 14px; text-align: justify;">Now again check the current version used on your system.</p>
<div class="linux-highlight"><span style="font-size: 13px;">[root@localhost /]# java -version<br />
</span></div>
<p><span style="font-size: 13px; color: #FF7200;"><b>Example Output</b></span></p>
<div class="linux-highlight"><span style="font-size: 13px;">java version &#8220;1.7.0_09-icedtea&#8221;</span></div>
<p><br/>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kruders.com/linux/how-to-change-java-version-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing MySql Workbench in Fedora</title>
		<link>http://kruders.com/linux/installing-mysql-workbench-in-fedora/</link>
		<comments>http://kruders.com/linux/installing-mysql-workbench-in-fedora/#comments</comments>
		<pubDate>Thu, 21 Mar 2013 09:25:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql workbench]]></category>

		<guid isPermaLink="false">http://kruders.com/?p=3336</guid>
		<description><![CDATA[In this article, you will see how to install and launch Mysql Workbench in Fedora 18 1. Change root user su &#8211; OR sudo -i 2. Install Remi repository ** Remi Dependency on Fedora 18 **rpm -Uvh http&#8221;//download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm** Fedora 18 **rpm -Uvh http://rpms.famillecollet.com/remi-release-18.rpm 3. Install MySql Workbench yum &#8211;enablerop=remi install mysql-workbench 4. Launching MySql Workbench [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size: 14px;">
<p style="font-size: 14px; text-align: justify;">In this article, you will see how to install and launch Mysql Workbench in Fedora 18</p>
<p><span style="font-size: 15px; color: #FF7200;"><b>1. Change root user</b></span></p>
<div class="linux-highlight"><span style="font-size: 13px;">su &#8211;<br />
OR<br />
sudo -i<br />
</span></div>
<p><span style="font-size: 15px; color: #FF7200;"><b>2. Install Remi repository</b></span></p>
<div class="linux-highlight"><span style="font-size: 13px;"><span style="font-weight: normal;">** Remi Dependency on Fedora 18 **</span></br>rpm -Uvh http&#8221;//download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm</br></br><span style="font-weight: normal;">** Fedora 18 **</span></br>rpm -Uvh http://rpms.famillecollet.com/remi-release-18.rpm</span></div>
<p><span style="font-size: 15px; color: #FF7200;"><b>3. Install MySql Workbench</b></span></p>
<div class="linux-highlight"><span style="font-size: 13px;">yum &#8211;enablerop=remi install mysql-workbench</span></div>
<p><span style="font-size: 15px; color: #FF7200;"><b>4. Launching MySql Workbench</b></span></p>
<p style="font-size: 13px;">
Once MySQL Workbench has been installed it can be launched by selecting <b>Applications &#8211; > Programming &#8211; > MySQL Workbench</b> from the main menu.</p>
<p><span style="font-size: 13px;">MySQL Workbench can also be launched from command line on Linux.</span></p>
<div class="linux-highlight"><span style="font-size: 13px;">shell> /usr/bin/mysql-workbench</span></div>
<p><br/>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kruders.com/linux/installing-mysql-workbench-in-fedora/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logback Logging Example</title>
		<link>http://kruders.com/logback-2/logback-logging-example/</link>
		<comments>http://kruders.com/logback-2/logback-logging-example/#comments</comments>
		<pubDate>Thu, 31 Jan 2013 06:53:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Logback]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://kruders.com/?p=2929</guid>
		<description><![CDATA[In this article, you will see very basic logging using Logback. First create a new Java Project and configure it as Maven Project. For Reference, Click Here Add the following dependencies in pom.xml 1. Logback Configuration The following configuration generates simple logs on console.logback.xml 2. Logback in Java Program The following Java class is a [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size: 14px;">
<p style="font-size: 14px; text-align: justify;">In this article, you will see very basic logging using Logback.</p>
<p><span style="font-size: 13px;">First create a new <b>Java Project</b> and configure it as <b>Maven Project</b>. For Reference, <a style="color: #06C;font-weight: bold;" href="../maven/enable-maven-for-java-projects-in-eclipse/" target="_blank">Click Here</a></span></p>
<p><span style="font-size: 13px;">Add the following dependencies in pom.xml</b> </p>
<pre class="brush: xml; title: ; notranslate">
  &lt;dependencies&gt;
     &lt;dependency&gt;
         &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
         &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
         &lt;version&gt;1.0.7&lt;/version&gt;
     &lt;/dependency&gt;
     &lt;dependency&gt;
         &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
         &lt;artifactId&gt;logback-core&lt;/artifactId&gt;
         &lt;version&gt;1.0.7&lt;/version&gt;
     &lt;/dependency&gt;
  &lt;/dependencies&gt;
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>1. Logback Configuration</b></span></p>
<p style="font-size: 14px; text-align: justify;">The following configuration generates simple logs on console.<br/><br/><b>logback.xml</b></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;configuration&gt;
    &lt;appender name=&quot;consoleAppender&quot; class=&quot;ch.qos.logback.core.ConsoleAppender&quot;&gt;
        &lt;encoder&gt;
            &lt;pattern&gt;%d{HH:mm:ss.SSS} [%thread] %-5level  %logger{35} - %msg%n&lt;/pattern&gt;
        &lt;/encoder&gt;
    &lt;/appender&gt;
     
    &lt;root level=&quot;INFO&quot;&gt;
        &lt;appender-ref ref=&quot;consoleAppender&quot; /&gt;
    &lt;/root&gt;
&lt;/configuration&gt;
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>2. Logback in Java Program</b></span></p>
<p style="font-size: 14px; text-align: justify;">The following Java class is a very simple example that initializes, and then uses, the Logback logging library for Java applications.</p>
<pre class="brush: java; title: ; notranslate">
package com.kruders;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
public class HelloWorld {
static final Logger logger = LoggerFactory.getLogger(HelloWorld.class);
     
    public static void main(String[] args) {
        logger.info(&quot;Hello World!!!&quot;);
    }
}
</pre>
<p style="font-size: 14px; text-align: justify;">When you run the above example you&#8217;ll get an output like:</p>
<p style="font-size: 14px; text-align: justify;">
<b>12:26:48.079 [main] INFO   com.kruders.HelloWorld &#8211; Hello World!!!</b>
</p>
<p><br/>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kruders.com/logback-2/logback-logging-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Limit WordPress Search To Post Titles</title>
		<link>http://kruders.com/wordpress/limit-wordpress-search-to-post-titles/</link>
		<comments>http://kruders.com/wordpress/limit-wordpress-search-to-post-titles/#comments</comments>
		<pubDate>Wed, 16 Jan 2013 06:34:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://kruders.com/?p=2899</guid>
		<description><![CDATA[In this article, you will see how to limit your wordpress search to post titles only. WordPress version WordPress 3.5 Source Code $search .= &#8220;{$searchand}(($wpdb -> posts.post_title LIKE &#8216;{$n}{$term}{$n}&#8217;) OR ($wpdb -> posts.post_content LIKE &#8216;{$n}{$term}{$n}&#8217;))&#8221;; Remove the OR part (in bold) to make it specific to post title.$search .= &#8220;{$searchand}(($wpdb->posts.post_title LIKE &#8216;{$n}{$term}{$n}&#8217;))&#8221;; Source File Source [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size: 14px;">
<p style="font-size: 14px; text-align: justify;">In this article, you will see how to limit your wordpress search to post titles only.</p>
<p style="font-size: 14px; text-align: justify;">
<b style="font-size: 15px; color: #ff7200;">WordPress version </b></p>
<ul type="disc" style="padding-left: 20px;">
<li>WordPress 3.5</li>
</ul>
<p style="font-size: 14px; text-align: justify;">
<b style="font-size: 15px; color: #ff7200;">Source Code</b><br/><br />
<span style="font-size: 14px; text-align: left;">$search .= &#8220;{$searchand}(($wpdb -> posts.post_title LIKE &#8216;{$n}{$term}{$n}&#8217;) <b>OR ($wpdb -> posts.post_content LIKE &#8216;{$n}{$term}{$n}&#8217;)</b>)&#8221;;</span><br/><br />
Remove the OR part (in bold) to make it specific to post title.<br/><br/>$search .= &#8220;{$searchand}(($wpdb->posts.post_title LIKE &#8216;{$n}{$term}{$n}&#8217;))&#8221;;<br/></p>
<p style="font-size: 14px; text-align: justify;"><b style="font-size: 15px; color: #ff7200;">Source File</b></p>
<ul type="disc" style="padding-left: 20px;">
<li>Source code is located in <span style="color:#4CA6CF">wp-includes/query.php.</span></li>
</ul>
<p><br/>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kruders.com/wordpress/limit-wordpress-search-to-post-titles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JDBC Introduction</title>
		<link>http://kruders.com/jdbc/jdbc-introduction/</link>
		<comments>http://kruders.com/jdbc/jdbc-introduction/#comments</comments>
		<pubDate>Wed, 16 Jan 2013 06:07:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JDBC]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdbc]]></category>

		<guid isPermaLink="false">http://kruders.com/?p=2895</guid>
		<description><![CDATA[The Java Database Connectivity (JDBC) API is the industry standard for database-independent connectivity between the Java programming language and a wide range of databases SQL databases and other tabular data sources, such as spreadsheets or flat files. The JDBC API provides a call-level API for SQL-based database access. JDBC technology also provides a common base [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size: 14px;">
<p style="font-size: 14px; text-align: justify;">The Java Database Connectivity (JDBC) API is the industry standard for database-independent connectivity between the Java programming language and a wide range of databases SQL databases and other tabular data sources, such as spreadsheets or flat files. The JDBC API provides a call-level API for SQL-based database access. JDBC technology also provides a common base on which tools and alternate interfaces can be built.</p>
<p><span style="font-size: 15px; color: #ff7200;"><b>JDBC Architecture</b></span></p>
<p><span style="font-size: 14px; color: #ff7200;"><b>Two-tier and Three-tier Processing Models</b></span></p>
<p style="font-size: 14px; text-align: justify;">The JDBC API supports both two-tier and three-tier processing models for database access.</p>
<p style="font-size: 14px; text-align: justify;">In the two-tier model, a Java applet or application talks directly to the data source. This requires a JDBC driver that can communicate with the particular data source being accessed. A user&#8217;s commands are delivered to the database or other data source, and the results of those statements are sent back to the user. The data source may be located on another machine to which the user is connected via a network. This is referred to as a client/server configuration, with the user&#8217;s machine as the client, and the machine housing the data source as the server. The network can be an intranet, which, for example, connects employees within a corporation, or it can be the Internet.</p>
<p style="font-size: 14px; text-align: justify;">In the three-tier model, commands are sent to a &#8220;middle tier&#8221; of services, which then sends the commands to the data source. The data source processes the commands and sends the results back to the middle tier, which then sends them to the user. MIS directors find the three-tier model very attractive because the middle tier makes it possible to maintain control over access and the kinds of updates that can be made to corporate data. Another advantage is that it simplifies the deployment of applications. Finally, in many cases, the three-tier architecture can provide performance advantages.</p>
<p><span style="font-size: 15px; color: #ff7200;"><b>JDBC API</b></span></p>
<p style="font-size: 14px; text-align: justify;">The JDBC API is comprised of two packages:</p>
<ul type="disc" style="padding-left: 20px;">
<li><a href="http://docs.oracle.com/javase/7/docs/api/java/sql/package-summary.html">java.sql</a></li>
<li><a href="http://docs.oracle.com/javase/7/docs/api/javax/sql/package-summary.html">javax.sql</a></li>
</ul>
<p>The JDBC API provides the following interfaces and classes:
</p>
<div class="reference">Reference</p>
<p><a style="color:white;text-decoration:underline;" href="http://docs.oracle.com/javase/tutorial/jdbc/overview/index.html" target="_blank">http://docs.oracle.com/javase/tutorial/jdbc/overview/index.html</a></div>
<p><br/>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kruders.com/jdbc/jdbc-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring + Log4j + Maven Example</title>
		<link>http://kruders.com/spring/spring-log4j-maven-example/</link>
		<comments>http://kruders.com/spring/spring-log4j-maven-example/#comments</comments>
		<pubDate>Tue, 15 Jan 2013 10:02:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[log4j]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://kruders.com/?p=2878</guid>
		<description><![CDATA[In this tutorial, I will show you how to integrate Spring 3 with Log4j. Tools and technologies used : Spring Log4j Maven Eclipse Following example demonstrates a simple Hello World web application using Spring MVC that will show logging message on Console. First create a new Dynamic Web Project and configure it as Maven Project. [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size: 14px;">
<p style="font-size: 14px; text-align: justify;">In this tutorial, I will show you how to integrate Spring 3 with Log4j.</p>
<p>Tools and technologies used : </p>
<ul type="disc" style="padding-left: 20px;">
<li>Spring</li>
<li>Log4j</li>
<li>Maven</li>
<li>Eclipse</li>
</ul>
<p style="font-size: 14px; text-align: justify;">Following example demonstrates a simple Hello World web application using Spring MVC that will show logging message on Console.</p>
<p><span style="font-size: 14px;">First create a new <b>Dynamic Web Project</b> and configure it as <b>Maven Project</b>. For Reference, <a style="color: #06c; font-weight: bold;" href="../maven/enable-maven-for-dynamic-web-projects-in-eclipse/" target="_blank">Click Here</a></span></p>
<p><span style="font-size: 14px;">Add the following dependencies in pom.xml </span></p>
<pre class="brush: xml; title: ; notranslate">
  &lt;properties&gt;
		&lt;spring.version&gt;3.0.5.RELEASE&lt;/spring.version&gt;
  &lt;/properties&gt;

  &lt;dependencies&gt;

		&lt;!-- Spring 3 dependencies --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-core&lt;/artifactId&gt;
			&lt;version&gt;${spring.version}&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-web&lt;/artifactId&gt;
			&lt;version&gt;${spring.version}&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
			&lt;version&gt;${spring.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
		    &lt;groupId&gt;log4j&lt;/groupId&gt;
		    &lt;artifactId&gt;log4j&lt;/artifactId&gt;
		    &lt;version&gt;1.2.17&lt;/version&gt;
	    &lt;/dependency&gt;
  &lt;/dependencies&gt;
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>1. Controller</b></span></p>
<p style="font-size: 14px; text-align: justify;">To provide a basic infrastructure, all of Spring&#8217;s various Controller inherit from <b>AbstractController</b>. When using the AbstractController as the baseclass for your controllers you only have to override the <b>handleRequestInternal(HttpServletRequest, HttpServletResponse)</b> method, implement your logic, and return a ModelAndView object.<br/><br/><b>HelloWorldController.java</b></p>
<pre class="brush: java; highlight: [9,12]; title: ; notranslate">
package com.kruders.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class HelloWorldController extends AbstractController{
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		ModelAndView model = new ModelAndView(&quot;helloworld&quot;);
		model.addObject(&quot;message&quot;, &quot;Hello World!!!&quot;);
		return model;
	}
}
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>2. Create View</b></span></p>
<p style="font-size: 14px; text-align: justify;">Create <b>jsp</b> folder in <b>WEB-INF</b> and create <b>helloworld.jsp</b> file in jsp folder<br/><br/>Now write the following code in helloworld.jsp file </p>
<pre class="brush: java; title: ; notranslate">
${message}
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>3. Configuration</b></span></p>
<p style="font-size: 14px; text-align: justify;">Create Spring Bean Configuration in <b>WEB-INF</b> folder and name it <b>dispatcher-servlet.xml</b> and add the following code. </p>
<pre class="brush: xml; title: ; notranslate">
&lt;bean name=&quot;/helloworld.html&quot; class=&quot;com.kruders.controller.HelloWorldController&quot; /&gt;
 
&lt;bean
    class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;&gt;
    &lt;property name=&quot;prefix&quot;&gt;
        &lt;value&gt;/WEB-INF/jsp/&lt;/value&gt;
    &lt;/property&gt;
     
    &lt;property name=&quot;suffix&quot;&gt;
        &lt;value&gt;.jsp&lt;/value&gt;
    &lt;/property&gt;
&lt;/bean&gt;
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>4. Integrate Spring in Web App</b></span></p>
<p style="font-size: 14px; text-align: justify;">To integrate Spring in Web Application, write the following code in <b>web.xml</b></p>
<pre class="brush: xml; title: ; notranslate">
&lt;servlet&gt;
    &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
&lt;/servlet&gt;
 
&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
 
&lt;context-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;/WEB-INF/dispatcher-servlet.xml&lt;/param-value&gt;
&lt;/context-param&gt;
 
&lt;listener&gt;
    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
&lt;/listener&gt;
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>5. Properties file</b></span></p>
<p style="font-size: 14px; text-align: justify;">Create log4j.properties file that defines standard rules required for Log4J to handle logging messages.<br/><br/><b>log4j.properties</b></p>
<pre class="brush: java; title: ; notranslate">
log4j.rootLogger=DEBUG, CA

log4j.appender.CA=org.apache.log4j.ConsoleAppender

log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>6. Integrate Log4j in Spring MVC</b></span></p>
<p style="font-size: 14px; text-align: justify;">Create a Class variable for Logger as shown below:</p>
<pre class="brush: java; highlight: [12,15]; title: ; notranslate">
package com.kruders.controller;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(&quot;/helloworld.html&quot;)
public class HelloWorldController {
	static final Logger logger = Logger.getLogger(HelloWorldController.class);
	@RequestMapping(method = RequestMethod.GET)
	public String printWelcome(ModelMap model) {
		logger.info(&quot;Hello World!!!&quot;);
		model.addAttribute(&quot;message&quot;, &quot;Hello World!!!&quot;);
		return &quot;helloworld&quot;;

	}
}
</pre>
<p style="font-size: 14px; text-align: justify;">When you run the above example you&#8217;ll get an output (on console) like:</p>
<p style="font-size: 14px; text-align: justify;">
<b>1531 [http-8181-2] INFO  com.kruders.controller.HelloWorldController  &#8211; Hello World!!!</b>
</p>
<p><br/>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kruders.com/spring/spring-log4j-maven-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spring + Hibernate + MySql + Maven Example</title>
		<link>http://kruders.com/spring/spring-hibernate-mysql-maven-example/</link>
		<comments>http://kruders.com/spring/spring-hibernate-mysql-maven-example/#comments</comments>
		<pubDate>Tue, 15 Jan 2013 05:08:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://kruders.com/?p=2876</guid>
		<description><![CDATA[In this tutorial, I will show you how to integrate Hibernate with Spring 3. Tools and technologies used : Hibernate Spring MySql Maven Eclipse First create a new Dynamic Web Project and configure it as Maven Project. For Reference, Click Here Add the following dependencies in pom.xml 1. Sql Script Use the following Sql Script [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size: 14px;">
<p style="font-size: 14px; text-align: justify;">In this tutorial, I will show you how to integrate Hibernate with Spring 3.</p>
<p>Tools and technologies used : </p>
<ul type="disc" style="padding-left: 20px;">
<li>Hibernate</li>
<li>Spring</li>
<li>MySql</li>
<li>Maven</li>
<li>Eclipse</li>
</ul>
<p><span style="font-size: 14px;">First create a new <b>Dynamic Web Project</b> and configure it as <b>Maven Project</b>. For Reference, <a style="color: #06c; font-weight: bold;" href="../maven/enable-maven-for-dynamic-web-projects-in-eclipse/" target="_blank">Click Here</a></span></p>
<p><span style="font-size: 14px;">Add the following dependencies in pom.xml </span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;properties&gt;
	&lt;spring.version&gt;3.1.0.RELEASE&lt;/spring.version&gt;
  &lt;/properties&gt;

  &lt;dependencies&gt;

	&lt;!-- Spring 3 dependencies --&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework&lt;/groupId&gt;
		&lt;artifactId&gt;spring-core&lt;/artifactId&gt;
		&lt;version&gt;${spring.version}&lt;/version&gt;
	&lt;/dependency&gt;

	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework&lt;/groupId&gt;
		&lt;artifactId&gt;spring-web&lt;/artifactId&gt;
		&lt;version&gt;${spring.version}&lt;/version&gt;
	&lt;/dependency&gt;

	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework&lt;/groupId&gt;
		&lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
		&lt;version&gt;${spring.version}&lt;/version&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
        &lt;groupId&gt;mysql&lt;/groupId&gt;
        &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
        &lt;version&gt;5.1.15&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
        &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
        &lt;version&gt;3.6.3.Final&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;javassist&lt;/groupId&gt;
        &lt;artifactId&gt;javassist&lt;/artifactId&gt;
        &lt;version&gt;3.12.1.GA&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
        &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
        &lt;version&gt;1.6.6&lt;/version&gt;
    &lt;/dependency&gt;

  &lt;/dependencies&gt;
</pre>
<p><span style="font-size: 15px; color: #FF7200;"><b>1. Sql Script</b></span><br />
<span style="font-size: 13px;"><br/>Use the following Sql Script for creating table.</span></p>
<pre class="brush: sql; title: ; notranslate">
create table User(
    ID int(10) primary key NOT NULL AUTO_INCREMENT,
    username varchar(50),
    password varchar(50));
</pre>
<p><span style="font-size: 15px; color: #FF7200;"><b>2. Pojo</b></span><br />
<span style="font-size: 13px;"><br/>Now create User class that maps java class to User table.<br/><br/><b>User.java</b></span></p>
<pre class="brush: java; title: ; notranslate">
package com.kruders.model.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = &quot;User&quot;)
public class User{
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    private Integer Id;
    @Column(name=&quot;username&quot;)
    private String username;
    @Column(name=&quot;password&quot;)
    private String password;
	public Integer getId() {
		return Id;
	}
	public void setId(Integer id) {
		Id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	} 
  
}
</pre>
<p><span style="font-size: 15px; color: #FF7200;"><b>3. Hibernate Configuration File</b></span><br />
<span style="font-size: 13px;"><br/>Now create the hibernate configuration file and add all the mapping files.<br/><br />
<b>hibernate.cfg.xml</b></span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE hibernate-configuration PUBLIC
		&quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;
		&quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;
&lt;hibernate-configuration&gt;
&lt;session-factory&gt;
	&lt;property name=&quot;hibernate.connection.driver_class&quot;&gt;com.mysql.jdbc.Driver&lt;/property&gt;
	&lt;property name=&quot;hibernate.connection.url&quot;&gt;jdbc:mysql://localhost:3306/test&lt;/property&gt;
	&lt;property name=&quot;hibernate.connection.username&quot;&gt;root&lt;/property&gt;
	&lt;property name=&quot;hibernate.connection.password&quot;&gt;password&lt;/property&gt;
	&lt;property name=&quot;connection.pool_size&quot;&gt;1&lt;/property&gt;
	&lt;property name=&quot;hibernate.dialect&quot;&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
	&lt;property name=&quot;show_sql&quot;&gt;true&lt;/property&gt;
	&lt;mapping class=&quot;com.kruders.model.bean.User&quot; /&gt;
&lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;
</pre>
<p><span style="font-size: 15px; color: #FF7200;"><b>4. Hibernate Utility Class</b></span><br />
<span style="font-size: 13px;"><br/>Now create <b>HibernateUtil</b> class. The HibernateUtil class helps in creating the SessionFactory from the Hibernate configuration file. A org.hibernate.SessionFactory is used to obtain org.hibernate.Session instances. A org.hibernate.Session represents a single-threaded unit of work. The org.hibernate.SessionFactory is a thread-safe global object that is instantiated once.</span></p>
<pre class="brush: java; title: ; notranslate">
package com.kruders.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
  
public class HibernateUtil {
  
    private static final SessionFactory sessionFactory = buildSessionFactory();
  
    private static SessionFactory buildSessionFactory() {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            return new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println(&quot;Initial SessionFactory creation failed.&quot; + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
  
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>5. Model</b></span></p>
<p style="font-size: 14px; text-align: justify;">Following is the Login class.</p>
<pre class="brush: java; title: ; notranslate">
package com.kruders.domain;
 
public class Login {
    String email;
    String password;
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
}
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>6. Controller</b></span></p>
<p style="font-size: 14px; text-align: justify;">In order to handle spring forms, you need your controller to extend SimpleFormController. Following class shows you how to extend SimpleFormController<br/><br/><b>LoginController.java</b></p>
<pre class="brush: java; title: ; notranslate">
package com.kruders.controller;
 
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
 
import com.kruders.domain.Login;
 
public class LoginController extends SimpleFormController{
    public LoginController(){
        setCommandClass(Login.class);
        setCommandName(&quot;loginForm&quot;);
    }
    @Override
    protected ModelAndView onSubmit(Object command) throws Exception {
        Login login = (Login) command;
        return new ModelAndView(&quot;loginSuccess&quot;,&quot;login&quot;,login);
    }
}
</pre>
<p style="font-size: 14px; text-align: justify;">Extending SimpleFormController makes the controller to handle form requests. Here in LoginController contructor, controller will bind values to/from Spring&#8217;s form tags.</p>
<pre class="brush: java; title: ; notranslate">
public LoginController(){
    setCommandClass(Login.class);  //Spring form values gets stored into Login object
    setCommandName(&quot;loginForm&quot;);    //if loginForm is submitted, Spring will forward request to this Controller
}
</pre>
<p style="font-size: 14px; text-align: justify;">When loginForm is submitted, onsubmit() method will be executed to handle form&#8217;s request and return ModelAndView on success. All the forms field values will be submitted as Strings to the form controller.</p>
<p><span style="font-size: 15px; color: #ff7200;"><b>7. Form Validation</b></span></p>
<p style="font-size: 14px; text-align: justify;">To validate the form fields we have a seperate LoginValidator class that implements the Validator interface, override the validate() method perform all the validations.<br/><br/>Following in the LoginValidator class. </p>
<pre class="brush: java; title: ; notranslate">
package com.kruders.validator;

import java.util.List;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import com.kruders.domain.Login;
import com.kruders.model.bean.User;
import com.kruders.util.HibernateUtil;

import org.hibernate.Session;

public class LoginValidator implements Validator{
	@Override
	public boolean supports(Class&lt;?&gt; clazz) {
		return Login.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		Login loginuser = (Login) target;
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, &quot;email&quot;, &quot;email.required&quot;);
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, &quot;password&quot;, &quot;password.required&quot;);
		Session session = HibernateUtil.getSessionFactory().openSession();
        List&lt;User&gt; userList = session.createQuery(&quot;from User where username ='&quot; + loginuser.getEmail() + &quot;' and password ='&quot; + loginuser.getPassword() + &quot;'&quot;).list();
        if(userList.size() == 0) {
        	errors.reject(&quot;wrongcredential&quot;,&quot;Wrong Username or Password!!!&quot;);	
        }
        
	}
}

</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>8. Properties File</b></span></p>
<p style="font-size: 14px; text-align: justify;">A properties file to store all the error messages. Here we have the error messages in a seperate properties file so we add the error code, you can even add the error messages directly.<br/><br/><b>messages.properties</b></p>
<pre class="brush: xml; title: ; notranslate">
email.required = User Name is required
password.required = Password is required
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>9. View</b></span></p>
<p style="font-size: 14px; text-align: justify;">Following is the form login form that contains Spring&#8217;s Form Tags and display error message if any.<br/><br/><b>form:errors</b> tag to display errors in jsp files.<br/><br/><b>loginForm.jsp</b></p>
<pre class="brush: java; title: ; notranslate">
&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
	pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;%@ taglib uri=&quot;http://www.springframework.org/tags/form&quot; prefix=&quot;form&quot;%&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
&lt;title&gt;Login Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form:form method=&quot;POST&quot; commandName=&quot;loginForm&quot;&gt;
	&lt;table&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;/td&gt;
			&lt;td&gt;&lt;/td&gt;
			&lt;td&gt;&lt;form:errors/&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Email :&lt;/td&gt;
			&lt;td&gt;&lt;form:input path=&quot;email&quot; /&gt;&lt;/td&gt;
			&lt;td&gt;&lt;form:errors path=&quot;email&quot; cssClass=&quot;error&quot; /&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Password :&lt;/td&gt;
			&lt;td&gt;&lt;form:password path=&quot;password&quot; /&gt;&lt;/td&gt;
			&lt;td&gt;&lt;form:errors path=&quot;password&quot; cssClass=&quot;error&quot; /&gt;&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
	&lt;tr&gt;
			&lt;td colspan=&quot;3&quot;&gt;&lt;input type=&quot;submit&quot; value=&quot;Login&quot;&gt;&lt;/td&gt;
		&lt;/tr&gt;
&lt;/form:form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p style="font-size: 14px; text-align: justify;">On successful submission of loginform, <b>loginSuccess.jsp</b> page will be displayed. </p>
<pre class="brush: java; title: ; notranslate">
&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
    pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
&lt;title&gt;Login Successful&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
${login.email} successfully logged in&lt;br/&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><span style="font-size: 15px; color: #ff7200;"><b>10. Spring Bean Configuration</b></span></p>
<p style="font-size: 14px; text-align: justify;">We now declare the controller and validator for the loginform Spring Bean Configuration file.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;bean class=&quot;com.kruders.controller.LoginController&quot;&gt;
    &lt;property name=&quot;formView&quot; value=&quot;loginForm&quot; /&gt;
    &lt;property name=&quot;successView&quot; value=&quot;loginSuccess&quot; /&gt;
  
    &lt;!-- Map a validator --&gt;
    &lt;property name=&quot;validator&quot;&gt;
        &lt;bean class=&quot;com.kruders.validator.LoginValidator&quot; /&gt;
    &lt;/property&gt;
&lt;/bean&gt;
</pre>
<p style="font-size: 14px; text-align: justify;">Also add the properties file.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;bean id=&quot;messageSource&quot; class=&quot;org.springframework.context.support.ResourceBundleMessageSource&quot; p:basename=&quot;messages&quot; /&gt;
</pre>
<div class="download"><span style="font-size: 14px;">You can download the source code of this example <a href="../../content/spring/Spring_Hibernate.zip"><b>here.</b></a></span></div>
<p><br/>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kruders.com/spring/spring-hibernate-mysql-maven-example/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Next and Previous Links for same Category in WordPress</title>
		<link>http://kruders.com/wordpress/next-and-previous-links-for-same-category-in-wordpress/</link>
		<comments>http://kruders.com/wordpress/next-and-previous-links-for-same-category-in-wordpress/#comments</comments>
		<pubDate>Thu, 10 Jan 2013 05:32:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://kruders.com/?p=2864</guid>
		<description><![CDATA[I created a category and call it &#8220;WordPress&#8221;. Then I created some posts and assign &#8220;WordPress&#8221; as category for the posts. Now I want the next/previous to be shown for the same category only. WordPress version WordPress 3.5 Arguments function previous_post_link($format=&#8217;&#171; %link&#8217;, $link=&#8217;%title&#8217;, $in_same_cat = false, $excluded_categories = &#8221;) You can change the in_same_cat to [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size: 14px;">
<p style="font-size: 14px; text-align: justify;">I created a category and call it &#8220;WordPress&#8221;. Then I created some posts and assign &#8220;WordPress&#8221; as category for the posts. Now I want the next/previous to be shown for the same category only.</p>
<p style="font-size: 14px; text-align: justify;">
<b style="font-size: 15px; color: #ff7200;">WordPress version </b></p>
<ul type="disc" style="padding-left: 20px;">
<li>WordPress 3.5</li>
</ul>
<p style="font-size: 14px; text-align: justify;">
<b style="font-size: 15px; color: #ff7200;">Arguments</b></p>
<ul type="disc" style="padding-left: 20px; font-size: 12px;">
<li>function previous_post_link($format=&#8217;&laquo; %link&#8217;, $link=&#8217;%title&#8217;, $in_same_cat = false, $excluded_categories = &#8221;)</li>
</ul>
<p>You can change the <b>in_same_cat</b> to <b>true</b> to display the previous post in same cateogry. <br/><br/>Similarly you can show next post in the same category.<br/></p>
<p style="font-size: 14px; text-align: justify;"><b style="font-size: 15px; color: #ff7200;">Source File</b></p>
<ul type="disc" style="padding-left: 20px;">
<li>previous_posts_link() is located in <span style="color:#4CA6CF">wp-includes/link-template.php.</span></li>
<li>next_post_link() is located in <span style="color:#4CA6CF">wp-includes/link-template.php.</span></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kruders.com/wordpress/next-and-previous-links-for-same-category-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get URL Parameter Using Javascript</title>
		<link>http://kruders.com/javascript/get-url-parameter-using-javascript/</link>
		<comments>http://kruders.com/javascript/get-url-parameter-using-javascript/#comments</comments>
		<pubDate>Thu, 10 Jan 2013 04:26:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kruders.com/?p=2856</guid>
		<description><![CDATA[It is sometimes required to get the query parameters of an URL in JavaScript. So following example demonstrates how to get parameter value from a URL. Source Code]]></description>
				<content:encoded><![CDATA[<link href="../../content/css/jquery/attributes/addClass.css" media="screen" rel="stylesheet" type="text/css">
<script src="../../content/js/javascript-tutorials/readurl.js" type="text/javascript"></script></p>
<div style="font-size: 14px;">
<p style="font-size: 14px; text-align: justify;">It is sometimes required to get the query parameters of an URL in JavaScript. So following example demonstrates how to get parameter value from a URL.</p>
<p><span style="font-size: 15px; color: #ff7200;"><b>Source Code</b></span></p>
<pre class="brush: jscript; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
  
&lt;h4 id='div1'&gt;&lt;/h4&gt;
&lt;script&gt;
function getUrlParameter( name ) {
  name = name.replace(/[\[]/,&quot;\\\[&quot;).replace(/[\]]/,&quot;\\\]&quot;);
  var regexS = &quot;[\\?&amp;]&quot;+name+&quot;=([^&amp;#]*)&quot;;
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
	  document.getElementById('div1').innerHTML = 'No Parameter passed';
  else
	  document.getElementById('div1').innerHTML = 'You have passed val=' + results[1];
}
getUrlParameter('name');
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kruders.com/javascript/get-url-parameter-using-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate &#8211; @MappedSuperclass How to override column identifier</title>
		<link>http://kruders.com/hibernate/mappedsuperclass-override-column-identifier/</link>
		<comments>http://kruders.com/hibernate/mappedsuperclass-override-column-identifier/#comments</comments>
		<pubDate>Wed, 09 Jan 2013 10:01:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[hibernate]]></category>

		<guid isPermaLink="false">http://kruders.com/?p=2850</guid>
		<description><![CDATA[In this tutorial I will show how to override an attribute from mapped super class. 1. Sql Script Use the following Sql Script for creating table. 2. Pojo Now create GenericId and User Class as following.GenericId.java : an abstract class, annotated with @MappedSuperclass that have id column User.java : an @Entity class that extends the [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size: 14px;">
<p><span style="font-size: 14px;">In this tutorial I will show how to override an attribute from mapped super class.</span><br/><br />
<span style="font-size: 15px; color: #FF7200;"><b>1. Sql Script</b></span><br />
<span style="font-size: 14px;"><br/>Use the following Sql Script for creating table.</span></p>
<pre class="brush: sql; title: ; notranslate">
create table User(
    ID int(10) primary key NOT NULL AUTO_INCREMENT,
    Name varchar(50));
</pre>
<p><span style="font-size: 15px; color: #FF7200;"><b>2. Pojo</b></span><br />
<span style="font-size: 14px;"><br/>Now create GenericId and User Class as following.<br/><br/><b>GenericId.java</b> : an abstract class, annotated with @MappedSuperclass that have <b>id</b> column</span></p>
<pre class="brush: java; title: ; notranslate">
package com.kruders.model.bean;

import javax.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class GenericID {
	private Integer id;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
}
</pre>
<p><span style="font-size: 14px;"><br/><b>User.java</b> : an @Entity class that extends the super class and overriding the getters of the id.</span></p>
<pre class="brush: java; title: ; notranslate">
package com.kruders.model.bean;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = &quot;User&quot;)
@AttributeOverride(name = &quot;id&quot;, column = @Column(name = &quot;ID&quot;))
public class User extends GenericID{
	
	
	@Id
    @GeneratedValue
    private Integer Id;
    @Column(name=&quot;Name&quot;)
    private String name;
    @Column(name=&quot;content&quot;)
    
    @Override
    public Integer getId() {
		return Id;
	}
	public void setId(Integer id) {
		Id = id;
	}
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
</pre>
<p><span style="font-size: 15px; color: #FF7200;"><b>3. Hibernate Configuration File</b></span><br />
<span style="font-size: 14px;"><br/>Now create the hibernate configuration file and add all the mapping files.<br/><br />
<b>hibernate.cfg.xml</b></span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE hibernate-configuration PUBLIC
		&quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;
		&quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;
&lt;hibernate-configuration&gt;
&lt;session-factory&gt;
	&lt;property name=&quot;hibernate.connection.driver_class&quot;&gt;com.mysql.jdbc.Driver&lt;/property&gt;
	&lt;property name=&quot;hibernate.connection.url&quot;&gt;jdbc:mysql://localhost:3306/test&lt;/property&gt;
	&lt;property name=&quot;hibernate.connection.username&quot;&gt;root&lt;/property&gt;
	&lt;property name=&quot;hibernate.connection.password&quot;&gt;&lt;/property&gt;
	&lt;property name=&quot;connection.pool_size&quot;&gt;1&lt;/property&gt;
	&lt;property name=&quot;hibernate.dialect&quot;&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
	&lt;property name=&quot;show_sql&quot;&gt;true&lt;/property&gt;
	&lt;mapping class=&quot;com.kruders.model.bean.Employee&quot; /&gt;
	&lt;mapping class=&quot;com.kruders.model.bean.EmployeeDetail&quot; /&gt;
&lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;
</pre>
<p><span style="font-size: 15px; color: #FF7200;"><b>4. Hibernate Utility Class</b></span><br />
<span style="font-size: 14px;"><br/>Now create <b>HibernateUtil</b> class. The HibernateUtil class helps in creating the SessionFactory from the Hibernate configuration file. A org.hibernate.SessionFactory is used to obtain org.hibernate.Session instances. A org.hibernate.Session represents a single-threaded unit of work. The org.hibernate.SessionFactory is a thread-safe global object that is instantiated once.</span></p>
<pre class="brush: java; title: ; notranslate">
package com.kruders.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
  
public class HibernateUtil {
  
    private static final SessionFactory sessionFactory = buildSessionFactory();
  
    private static SessionFactory buildSessionFactory() {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            return new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println(&quot;Initial SessionFactory creation failed.&quot; + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
  
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}
</pre>
<p><span style="font-size: 15px; color: #FF7200;"><b>5. Run Program</b></span><br />
<span style="font-size: 14px;"><br/>Create <b>Main.java</></b> class that adds a record and run it as Java Application</span></p>
<pre class="brush: java; title: ; notranslate">
package com.kruders.core;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.kruders.model.bean.User;
import com.kruders.util.HibernateUtil;
public class Main {
    public static void main(String args[]) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction transaction = null;
        try {
            transaction = session.beginTransaction();
            User user = new User();
            user.setName(&quot;Puneet&quot;);
            session.save(user);
            transaction.commit();
        }catch (HibernateException e) {
            transaction.rollback();
            e.printStackTrace();
        } finally {
            session.close();
        }
    }
}
</pre>
<div class="download">
<span style="font-size: 13px;">You can download the source code of this example <a href="../../content/hibernate/OverrideColumnMappedSuperClass.zip"><b>here.</b></a></span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kruders.com/hibernate/mappedsuperclass-override-column-identifier/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
