Starting with Oracle9i, the confusing outer join syntax using the ‘(+)’ notation has been superseded by ISO 99 outer join syntax. As we know, there are three types of outer joins, left, right, and full outer join. The purpose of an outer join is to include non-matching rows, and the outer join returns these missing columns as NULL values.
Let’s review the syntax differences between these variations in join syntax:
Left outer join: Oracle8i
select
last_name,
department_name
from
employees e,
departments d
where
e.department_id = d.department_id(+);
Left outer join: Oracle9i
select
last_name,
department_name
from
employees e
left outer join
departments d
on
e.department_id = d.department_id;
|
I love programming
The reason for doing the work is to create something useful that helps people. Please click the ads if my articles are useful for you.
3/15/2013
So confusing Oracle left join
3/12/2013
iBatis and Log4j
- log4j.rootLogger=DEBUG, A2
- # SqlMap logging configuration...
- log4j.logger.com.ibatis=DEBUG
- log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
- log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
- log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
- log4j.logger.java.sql.Connection=DEBUG
- log4j.logger.java.sql.Statement=DEBUG
- log4j.logger.java.sql.PreparedStatement=DEBUG
- log4j.logger.java.sql.ResultSet=DEBUG
- # Console output...
- log4j.appender.stdout=org.apache.log4j.ConsoleAppender
- log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
- log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
- log4j.appender.A2=org.apache.log4j.FileAppender
- log4j.appender.A2.File=C:/dcsi/twacs.log
- # Truncate 'twacs' if it aleady exists.
- log4j.appender.A2.Append=true
- # Appender A2 uses the PatternLayout.
- log4j.appender.A2.layout=org.apache.log4j.PatternLayout
- log4j.appender.A2.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c %x - %m%n
- #log4j.appender.A2.layout.ConversionPattern=%-5r %-5p [%t] %c{2} - %m%n
3/09/2013
javascript code segments
In the gap of two sprints, I have sometime to review the basic knowledge. Here we go.
#1 Image
<img name="news" src="xxx">
js: document.images.news.src = xxxx;
you can also do this way,
newsOff = new Image();
newsOff.src = "xxx";
#2 Eval()
The eval() method handles nicely if you want to dynamically create JavaScript code.
e.g. eval(“document.images.news.src = xxxx;”
#1 Image
<img name="news" src="xxx">
js: document.images.news.src = xxxx;
you can also do this way,
newsOff = new Image();
newsOff.src = "xxx";
#2 Eval()
The eval() method handles nicely if you want to dynamically create JavaScript code.
e.g. eval(“document.images.news.src = xxxx;”
Examples of using Quartz
Here are some full examples:
| Expression | Meaning |
|---|---|
| 0 0 12 * * ? | Fire at 12pm (noon) every day |
| 0 15 10 ? * * | Fire at 10:15am every day |
| 0 15 10 * * ? | Fire at 10:15am every day |
| 0 15 10 * * ? * | Fire at 10:15am every day |
| 0 15 10 * * ? 2005 | Fire at 10:15am every day during the year 2005 |
| 0 * 14 * * ? | Fire every minute starting at 2pm and ending at 2:59pm, every day |
| 0 0/5 14 * * ? | Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day |
| 0 0/5 14,18 * * ? | Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day |
| 0 0-5 14 * * ? | Fire every minute starting at 2pm and ending at 2:05pm, every day |
| 0 10,44 14 ? 3 WED | Fire at 2:10pm and at 2:44pm every Wednesday in the month of March. |
| 0 15 10 ? * MON-FRI | Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday |
| 0 15 10 15 * ? | Fire at 10:15am on the 15th day of every month |
| 0 15 10 L * ? | Fire at 10:15am on the last day of every month |
| 0 15 10 ? * 6L | Fire at 10:15am on the last Friday of every month |
| 0 15 10 ? * 6L | Fire at 10:15am on the last Friday of every month |
| 0 15 10 ? * 6L 2002-2005 | Fire at 10:15am on every last friday of every month during the years 2002, 2003, 2004 and 2005 |
| 0 15 10 ? * 6#3 | Fire at 10:15am on the third Friday of every month |
| 0 0 12 1/5 * ? | Fire at 12pm (noon) every 5 days every month, starting on the first day of the month. |
| 0 11 11 11 11 ? | Fire every November 11th at 11:11am. |
Pay attention to the effects of '?' and '*' in the day-of-week and day-of-month fields!
2/27/2013
Code segments about JSTL
<c:set var="myuri" value="${pageContext.request.contextPath}" />
<c:choose>
<c:when test="${fn:contains(myuri, '/xxx')}">
<script type="text/javascript" src="javascript/xxx.js"></script>
</c:when>
<c:otherwise>
<script type="text/javascript" src="xxx.js"></script>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${fn:contains(myuri, '/xxx')}">
<script type="text/javascript" src="javascript/xxx.js"></script>
</c:when>
<c:otherwise>
<script type="text/javascript" src="xxx.js"></script>
</c:otherwise>
</c:choose>
2/23/2013
Struts2 + FreeMarker Tempalte (FTL)
Struts2 + FreeMarker Tempalte (FTL) Integration example
- By Viral Patel on August 28, 2012
Welcome to Freemarker Tutorial Series. In previous post we created Spring MVC based Hello World Freemarker Template example. We learned few APIs of freemarker and also how to integrate it with Spring MVC based application. Following are the list of tutorials from Freemarker tutorial series.
FreeMarker Tutorial Series
Today we will create a Struts2 based application that uses Freemarker FTL as view instead of JSP. This would give you a good insight in Struts2 + Freemarker integration. The application is similar to previous tutorial’s User app, where a list of users will be displayed and we can add new user.
The application is very simple:
- There is a table that displays user info like firstname, lastname.
- New user can be added via Add User form.
Below is the wireframe of our final Freemarker based Struts2 app.


So lets get started.
Things We Need
Before we starts with our Struts2 + FreeMarker example, we will need few tools.
- JDK 1.6 or above (download)
- Tomcat 6.x or above or any other container (Glassfish, JBoss, Websphere, Weblogic etc) (download)
- Eclipse 3.4.x or above (download)
- Struts 2.3.4.1 or above (download)
- Freemarker JAR v2.3.15 or above(download)
Let us start with our Struts2 based Freemarker application.
Step 1: Getting Started
Open Eclipse and goto File -> New -> Project and select Dynamic Web Project in the New Project wizard screen.

After selecting Dynamic Web Project, press Next.

Write the name of the project. For example Freemarker_Struts2_example. Once this is done, select the target runtime environment (e.g. Apache Tomcat v6.0). This is to run the project inside Eclipse environment. After this press Finish.
Once the project is created, you can see its structure in Project Explorer. This is how the project structure would look like when we finish the tutorial and add all source code.

Till this step, our basic Eclipse web project is ready. We will now add Struts2 and Freemarker support to this project.
Step 2: Adding Struts2 Support
First copy all required Struts2 JAR and supporting JAR files in WebContent > WEB-INF > lib folder. Create this folder if it does not exists. Don’t worry if you do not have these JARs. You can download the complete source code with JAR files at the end of this tutorial.
Next we change web.xml (deployment descriptor) and add Struts2 support to it. If you do not know why we do this, I strongly recommends you to go through Struts2 Tutorial series.
Related: Struts2 hello world example
Update the web.xml with following code:
File: /WebContent/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_9" version="2.4"> <display-name>Freemarker Struts2 example - viralpatel.net</display-name> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app> |
The above code in web.xml will define a filter
StrutsPrepareAndExecuteFilter and maps it with url pattern /*. Thus each request will go through the Struts2 framework and it will decide wheather an action is available which can be called or default action should be allowed. Also struts framework will try to load its configuration from struts.xml file. It expects this file to be present in classpath (WEB-INF/classes) of the application when the source is compiled. Thus we will create a source folder calledResources and put the struts.xml file in it.
To create a source folder, right click on your project in Project Explorer view of Eclipse and select New > Source Folder.

Specify folder name

Create a new file
Resources and press Finish.
Create a new file
struts.xml under Resources folder. Copy following code into it.
File: /Resources/struts.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <package name="default" extends="struts-default" namespace="/"> <action name="list" method="list" class="net.viralpatel.struts2.UserAction"> <result type="freemarker" name="success">/WEB-INF/ftl/index.ftl</result> </action> <action name="add" method="add" class="net.viralpatel.struts2.UserAction"> <result type="freemarker" name="success">/WEB-INF/ftl/index.ftl</result> </action> </package></struts> |
Note that in above configuration file, we have defined User action of our application. We defined two actions using
<action> tag. One to list the users and another to add new user. Note how we used attribute method="add" and method="list" to let Struts2 know which particular method needs to be called within the Action class. Also the result type mapped here is type="freemarker". Struts2 provides a first-class support to Freemarker template. All one has to do is to define result type freemarker. Struts automatically manage the view forwards in this case. On success of the action we forward the request to/WEB-INF/ftl/index.ftl freemarker view.Step 3: Create Struts2 Action
Create new Struts2 action class
UserAction under /src/net/viralpatel/struts2/ folder and copy following source code into it.
File: /src/net/viralpatel/struts2/UserAction.java
package net.viralpatel.struts2;import java.util.ArrayList;import java.util.List;import com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport { private static final long serialVersionUID = -8366209797454396351L; private static List<User> userList = new ArrayList<User>(); private User user; static { userList.add(new User("Bill", "Gates")); userList.add(new User("Steve", "Jobs")); userList.add(new User("Larry", "Page")); userList.add(new User("Sergey", "Brin")); userList.add(new User("Larry", "Ellison")); } /** * Action method to display user list. Uses <code>userList</code> array * object defined as class level attribute to display list of users. * @return SUCCESS */ public String list() { return SUCCESS; } /** * Action method to add new user. Read the user information * via <code>user</code> object defined as class level attribute. * @return SUCCESS if user is added successfully */ public String add() { System.out.println("User:"+user); userList.add(user); return SUCCESS; } public List<User> getUserList() { return userList; } public void setUserList(List<User> userList) { UserAction.userList = userList; } public User getUser() { return user; } public void setUser(User user) { this.user = user; }} |
In above Struts2 action class, we defined two methods:
add() and list() for our application. Also note that we have created a static ArrayList userList, which holds the user information. This is a dummy list just to mimic database values. In an ideal application, you may have to call Database and fetch list of users from a table. But for sake of simplicity we stores users in an arraylist.
Other than userList, we also defined
User user object as class attribute. This object will store the user information when a new user is added. It act as a form bean object for action class.
Apart from the above
UserController class, we will also need a bean class User which holds the user information like firstname, lastname etc.
File: /src/net/viralpatel/struts2/User.java
package net.viralpatel;public class User { private String firstname; private String lastname; public User() { } public User(String firstname, String lastname) { this.firstname = firstname; this.lastname = lastname; } //Add Getter and Setter methods} |
Now add Freemarker view in your project.
Step 4: Create Freemarker Template File
Create a new file
index.ftl under folder /WebContent/WEB-INF/ftl/. Copy following content into it.
File: /WebContent/WEB-INF/ftl/index.ftl
<html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" /> <title>ViralPatel.net - FreeMarker Spring MVC Hello World</title></head><body> <div id="header"> <h2><a href="http://viralpatel.net"><img height="37" width="236" border="0px" src= "http://viralpatel.net/blogs/wp-content/themes/vp/images/logo.png" align= "left" /></a> FreeMarker Struts2 Hello World</h2> </div> <div id="content"> <fieldset> <legend>Add User</legend> <@s.form action="add" method="post"> <@s.textfield label="First name" name="user.firstname"/> <@s.textfield label="Last name" name="user.lastname"/> <@s.submit value="Save"/> </@s.form> </fieldset><br /> <table class="datatable"> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <#list userList as user> <tr> <td>${user.firstname}</td> <td>${user.lastname}</td> </tr> </#list> </table> </div></body></html> |
This is a simple FTL template file. We just iterate model
userList list in a loop and prints user’sfirstname and lastname in table.
One last thing, the default index.jsp is opened when you tries to execute your application in eclipse. So just update it and add link to our User page. Modify the /WebContent/index.jsp file and add following code into it.
File: /WebContent/index.jsp
<html><head> <title>Welcome</title></head><body> <a href="list">Freemarker Struts2 example</a></body></html> |
That’s All Folks
You may want to run the application see the result. I assume you have already configured Tomcat in eclipse. All you need to do:
Open Server view from Windows > Show View > Server. Right click in this view and select New > Server and add your server details.
Open Server view from Windows > Show View > Server. Right click in this view and select New > Server and add your server details.
To run the project, right click on Project name from Project Explorer and select Run as > Run on Server (Shortcut: Alt+Shift+X, R)
URL: http://localhost:8080/Freemarker_Struts2_example/list


Subscribe to:
Posts (Atom)