Overview
To objective is to tell the Calendar object not to show timezone info (i.e. Show ‘2011-03-24′ instead of ‘2011-03-24+08:00′) when printing out date. One of the example is when using with XMLBeans.
Reference
suppressing time zone when printing an xsd:date : Weblogic
Calendar (Java 2 Platform SE v1.4.2) – clear(int)
Steps
The key is the Calendar.clear(int) function. We can use it to tell the Calendar object that time zone info is not set, thus the info will not be printed out.
Calendar calNoTz = Calendar.getInstance();
calNoTz.clear(Calendar.ZONE_OFFSET); // Clear the 'Zone offset' info
Overview
Remote desktop is one of my favorite Windows features. That’s one of the reasons why I only use Windows with professional+ edition.
Everyone who have used remote desktop knows that the host will be locked after the remote session is logged out. Sometimes this characteristic is not convenient to us. I found a tricks to work-around it on XP Pro.
Reference
Can I stop Remote Desktop from locking host?
Steps
The secret is very simple: run ”tscon.exe 0 /dest:console” command on the remote computer.
This command will terminate the remote desktop session and left the remote computer unlocked. It is tested on XP Pro (Doubt that it would work on Vista/Win7)
Overview
This blog serves as summary of links to useful Struts 2 Reference Materials. I only list the reference materials that I have read and found useful.
Reference
Getting Started Documents
- Struts 2 Documentation – Getting Started
Convention Plugin
- Struts 2 Documentation – Convention Pugin
Spring Integration / Spring Plugin
- Struts 2 Documentation – Spring Pugin
- Struts 2 Tutorial – Struts 2 + Spring 2 + JPA + AJAX
Tile Plugin
- Struts 2 Documentation – Tile Pugin
- Struts 2 Tiles Example – VaanNila
- Tiles 2 – Tutorial
Overview
I’ve heard of REST, or Representational State Transfer many times. My impression is on the SEO Url like http://bookstore.com/books/isdn/978-0-596-52926-0. Actually REST is much more than that, it can applies on HTTP and many other protocols. And by learning REST, we can design/develope better web sites.
Below are some good sites about REST, they are good for learning as well as reminding on REST’s concepts.
Reference
- Why REST Failed – The Cafes
- REST for Java developers, Part 1 – JavaWorld
- Why PUT and DELETE – artima developer
Overview
Recently I just started playing with JPA (I used Hibernate and JDBC before). After reading some examples, I built a very simple program with JPA 2.0 (EclipseLink 2.1), Eclipse 3.5 Galileo and MySQL Server 5.1. I would like to summarize steps to build the program here.
Reference
- EclipseLink 2.1.0 download page
- Connector/J – MySQL JDBC driver
- A Java Persistence Example
- HelloWorld with JPA, TopLink and MySql
Steps
Download EclipseLink 2.1 and JDBC driver for MySQL Server 5.1
Use the above reference links to download EclipseLink 2.1 and MySQL 5.1 JDBC Driver. The JAR files we needed are eclipselink.jar, javax.persistence_2.0.1.v201006031150.jar and mysql-connector-java-5.1.13-bin.jar
Create Table
Use this SQL to create table bookbank for the example
DROP TABLE IF EXISTS `bookbank`;
CREATE TABLE `bookbank` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(45) NOT NULL DEFAULT '',
`author` varchar(45) NOT NULL DEFAULT '',
`price` double DEFAULT NULL,
PRIMARY KEY (`id`)
)
Create a Connection Profile in Eclipse
A Connection Profile let you define a DB Connection and view Table Schema and Data in it. and the best part is it can generated Entity Bean for you according to connected DB Schemas!
- Start "Eclipse", choose "File" –> "New" –> "Other…". Select "Connection Profile" in the wizard
- At New Connection Profile, select MySQL for Connection Profile Type. Enter the name of the connection profile. Click Next
- At next page. You have to choose a driver definition. If you don’t already have a MySQL 5.1 driver definition, you have to create it here. Click the "New Driver Definition" button (red rectangle) to do that.
You can jump to step 6 if you already have a MySQL 5.1 driver definition.
- At New Driver Definition, select the driver template with System Version 5.1. Enter MySQL 5.1 as the driver name. Click "Jar List" tab
- At "Jar List" tab, remove any existing jar listed here. Than click "Add JAR/Zip…" and choose the mysql-connector-java-5.1.13-bin.jar file you just downloaded.
Then click "OK" to create the definition
- Back to the "New Connection Profile" window, choose the MySQL 5.1 driver definition you just created. Enter the Database, URL, Username and password for the connection. Remember to check "Save password" for future connection. Click "Finish" to create the profiile.
Create JPA Project in Eclipse
Next we have to create a JPA project in Eclipse.
- Start "Eclipse", choose "File" –> "New" –> "Project…". Select "JPA Project" in the wizard
- At "New JPA Project", enter project name. Select <None> for "Target runtime". Click "Next" twice
- At this page, use the values listed below:
- "Platform": Generic
- "JPA Implementation": Disable Library Configuration (we will add the EclipseLink library manually)
- "Connection": Choose the connection profile you have just created
Note: If you select "Add driver library to build path", the driver library used in your connection profile will be added to the project. Otherwise you need to manually add the correct driver library.
- Click "Finish" to create the project
Create Entity Bean from DB Table
- In the JPA projec, add reference to eclipselink.jar, javax.persistence_2.0.1.v201006031150.jar libraries
- Right click on the JPA project, select "New" –> "Entities From Tables"
- The connection profile should be automatically selected, choose the bookbank table. Click "Next" three times
- At this page, choose "identity" for "Key generator". Click "Finish"
Modify persistence.xml File
- Open the "persistence.xml" file inside folder "META-INF", replace the "persistence-unit" tag with the following content:
<persistence-unit name="JpaTest" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>Bookbank</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpa_test" />
<property name="javax.persistence.jdbc.user" value="MySQL_user_id" />
<property name="javax.persistence.jdbc.password" value="MySQL_password" />
</properties>
</persistence-unit>
Create the testing console app
Now it’s time to test our JPA app! Let’s add a Java Class with the following code to the JPA project.
public class TestMain {
public static void main(String[] args) {
EntityManager em = Persistence
.createEntityManagerFactory("JpaTest")
.createEntityManager();
EntityTransaction t = em.getTransaction();
t.begin();
Bookbank book = new Bookbank();
book.setTitle("test title");
book.setAuthor("test author");
book.setPrice(123.456);
em.persist(book);
t.commit();
t.begin();
Bookbank resultBook = (Bookbank)em
.createQuery("select b from Bookbank b order by b.id desc")
.setMaxResults(1)
.getSingleResult();
System.out.println("Query result:");
System.out.println("Id: " + resultBook.getId()
+ ", title: " + resultBook.getTitle()
+ ", author: " + resultBook.getAuthor()
+ ", price: " + resultBook.getPrice());
t.commit();
em.close();
System.exit(0);
}
}
What the class do is simply insert a record with hardcoded values into bookbank table, and then select the newest record. We can start the "TestMain" class in Eclipse by right-clicking the class, "Run As" –> "Java Application"

Overview
How to make a program to run whenever a new message is received on a specific queue? There are two ways to implement this "MQ trigger" features:
- Use triggers function of WebSphere MQ
WebSphere MQ have a function called "Trigger Monitor". It can listen to queue continuously and trigger a program(written by you) to run when messages are received.
To use this function you (at least) have to:
- Configure the MQ Server for trigger (e.g. create / associate initiation queue)
- Write the program to handle the trigger event, usually this is a standalone program
- Configure and start Trigger Monitor to monitor the target initiaition queue
I did not use this method for MQ triggering, as this method seems quite troublesome and require lots of configuration. Instead I use the next method to achieve MQ trigger. You may refer to this WebSphere MQ help page for more info on this method.
- Deploy a Message-Driven Bean to WebSphere App Server connected to the MQ
A "Message-Driven Bean" (MDB) is an "Enterprise Java Bean" (EJB) which acts as a JMS message listener. It can listen to a port and be started when a JMS message arrive. For more info, please refer to this J2EE Tutorial.
To use JMS technology to achieve MQ triggering function, we first need a WebSphere Application Server (I used WebSphere v6.0). Other J2EE App Server would need WebSphere MQ integration to work. Then we need to configure WebSphere MQ as JMS provider in the App Server. After that, we have to configure some JMS stuff on the App Server, write the MDB and deploy it.
This great tutorial at IBM have everything you need to know to do MQ trigger thru JMS. It even come with sample code! Please refer to this page for importing the sample code.
I would try to outline the steps here:
- Create the queue (As I already have a queue I skipped this step)
- Define the JMS connection factory for WebSphere MQ
- Define the JMS queue
- Define the listener ports
- Write the MDB, deploy it to App Server
- Restart App Server, done!
Reference
- Starting WebSphere MQ applications using triggers
- Make WebSphere MQ the JMS provider for Apps deployed in WebSphere
- How WebSphere Application Server V6 handles poison messages
- What Is a Message-Driven Bean? – The J2EE Tutorial
Overview
Recently I have a task to change all the “last_update_date” column in our tables to store UTC (GMT) time. The “last_update_date” column with data type DATE stores the datetime where the row is last updated.
I found that the system originally use SYSDATE to populate the value of “last_update_date” column, and the value of SYSDATE depends on DB server’s time zone.
There are two ways to get SYSDATE in UTC (GMT) time:
- Use function SYS_EXTRACT_UTC(SYSTIMESTAMP)
Use function SYS_EXTRACT_UTC(SYSTIMESTAMP) to get SYSTIMESTAMP in UTC time. In my Oracle 9i DB I can save this directly to a column with date type DATE.
- SYSTIMESTAMP is very similar to SYSDATE except that it also includes fractional seconds and time zone.
- SYS_EXTRACT_UTC is a function to shows a TIMESTAMP with UTC time. SELECT SYSTIMESTAMP, SYS_EXTRACT_UTC(SYSTIMESTAMP) FROM DUAL;
Result:
SYSTIMESTAMP
---------------------------------------------------------------------------
12-AUG-10 11.54.45.147229 AM +08:00
SYS_EXTRACT_UTC(SYSTIMESTAMP)
---------------------------------------------------------------------------
12-AUG-10 03.54.45.147229 AM
- Alter session time zone and use CURRENT_DATE instead of SYSDATE
Because SYSDATE depends on OS of the DB Server, we cannot change its time zone setting. However, we can change the time zone of current session and use CURRENT_DATE instead of SYSDATE to get date according to current session time zone.
ALTER SESSION SET TIME_ZONE = '00:00';
SELECT CURRENT_DATE FROM DUAL;
Reference
- SYS_EXTRACT_UTC – Oracle SQL Reference
- SYSTIMESTAMP – Oracle SQL Reference
- CURRENT_DATE – Oracle SQL Reference
Overview
Eclipse is a popular IDE for Java/J2EE development. But indeed it can be used for developing on other languages too! Eclipse PHP Development Tools (PDT) is a powerful plugin for PHP development, it includes the following features:
- Code Assist (Intelli-sense)
- PHP Debug perspective which is very similar to Java Debug perspective
- PHP project template
In this blog, we will see how to quickly setup a PHP development environment with Eclipse PDT. Below shows the initial configuration:
- Windows 2003 with IIS 6.0
- Eclipse 3.5 Galileo
Reference
- Debugging PHP using Eclipse and PDT (pdf)
- Microsoft Web Platform Installer 2.0
- Eclipse 3.5 (Galileo) update site
- “xdebug” HomePage
Steps
Install PHP 5.2.14
I used "Microsoft Web Platform Installer (WPI) 2.0" to install and configure PHP. The procedures are quite simple:
- Download and install WPI here
- Start WPI, select "Web Platform" on the left pane, then click "Customize" under "Web Server"
- Check "FastCGI 1.5 for IIS 6.0 and IIS 5.1", click "Back to Web Platform"
- Click "Customize" under "Frameworks and Runtimes", check all two items under "PHP"
- Click "Install" button to install the selected components
Install PDT on Eclipse 3.5 Galileo
Installing PDT is easy as it can be found in the Eclipse update site
- Start Eclipse and go to "Help" –> "Install New Software…"
- Select or add the Eclipse Galileo update site http://download.eclipse.org/releases/galileo
- PDT is under "Programming Languages"
Setup “xdebug” for PHP debugging
Although PDT have a PHP debug perspective, you have to install a PHP debugger to use it. There are two debugger supported by PDT: "Zend Debugger" and "xdebug". I’ve tried using both of them, and find that there is a problem debugging PHP web pages with Zend Debugger. On the other hand, xdebug works great. So I will use xdebug in this post.
To set up xdebug on Windows 2003, you need to download the precompiled dll from xdebug site and modify your php.ini file accordingly:
- Download the right dll at “xdebug” HomePage, the dll I use is php_xdebug-2.1.0-5.2-vc6-nts.dll
- Put the dll in a local folder, I use C:\Program Files\PHP\ext (PHP extension folder)
- Add the following line to the PHP configure file, mine is C:\Program Files\PHP\php.ini
[xdebug]
zend_extension="C:\Program Files\PHP\ext\php_xdebug-2.1.0-5.2-vc6-nts.dll"
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
- Restart IIS and verify that the phpinfo() page contains a section for xdebug
Try it out!
With the previous step done, now it’s time to test out our setting! You may follow this pdf guide to create a test PHP project and tty the debugging function. The guide also tell you how to setup PDT and debugger, you can skip those parts as they are already done.
Overview
Here are the two major problems I always face when storing videos taken by my DC:
- Convert video from MOV to other format (and keeping good video/audio quality)
- Rotate video from landscape to portrait (as the video is taken vertically)
I want to do this because I want to play the videos on my PC or TV (via PlayStation 3). After trying a number of softwares I settle with the following two great open source freewares:
- MP4Cam2AVI Easy Converter by graywolf2004
- VirtualDub by Avery Lee
The first software, as its name suggests, is used to convert MOV videos to AVI format. It provides MPEG-4 video and MP3 audio compression. I found that its performance is high and output quality is quite good.
The second is a famous free video editing tool. It is originally designed for handling AVI video, so I need to convert MOV videos first to use it. On the other hand, there are a number of third-party plugins for this software, including the plugin for importing MOV videos. Bad news is I have tried that plugin but still cannot edit MOV file.
Note:
In order to import MP4 videos into VirtualDub, you need to install ffdshow and its plugin for VirtualDub (included in the install package). Otherwise you will not see anything but black screen on VirtualDub.
Reference
- MP4Cam2AVI Easy Converter
- VirtualDub
- ffdshow
- VirtualDub rotate video demo – YouTube by proditech
Overview
Learning Spring Framework is somewhat diffcult as there are too many Products on SpringSource.org. I just can’t figure out where to start. One way to sort things out is to ignore all Spring features except the core one: Spring IoC container.
Below listed two very good pages for learning Spring Framework quickly. The first one explains the core feature of Spring container: Dependency Injection (DI), and use a very simple (maybe the simplest IMHO) HelloWorld example to illustrate the idea. The example is super simple, with no extra Spring features at all (it is not even a Web App!)
The second web pages contains many Spring tutorials, each on a Spring’s feature. It’s good for learning Spring’s features one at a time.
Reference
- A Spring Jump Start
- Spring Tutorial – VaanNila