Quick Setup a Project Using JDBC & Derby DB/Java DB

Categories: DatabaseJava; Tagged with: ; @ May 8th, 2014 0:03

Set up Maven dependences



Connect to the DB using JDBC

This method will print out all Tables;  // before you do anything with the Database, there should be some System tables already.

package com.liguoliang;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCTest {

	private static final String DB_URL = "jdbc:derby:tempDBForTest;create=true";	
	public static void main(String[] args) {
	    Connection conn = null ;
	    try {
	        Class.forName("org.apache.derby.jdbc.EmbeddedDriver") ;
	        conn = DriverManager.getConnection(DB_URL);
			PreparedStatement ps = conn.prepareStatement(sql);
	        ResultSet rs = ps.executeQuery();
	        while (rs.next()) {
				System.out.println("Rs: " + rs.getString(1));
	    } catch (SQLException se) {
	    } catch(ClassNotFoundException e){
	        System.out.println("JDBC Driver not found in CLASSPATH") ;
	    }finally {
	        if(conn != null){
	                conn.close() ;
	            } catch(SQLException se){


Use Eclipse to manage your Derby

Switch to ‘Database Development’ perspective, you may create/manage  Derby DB/table.

Maven Assembly Plugin Example

Categories: Development Notes; Tagged with: ; @ April 27th, 2014 0:22


Generate a distributable archive.


<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">


      <!-- <filters>
      </filters> -->


Maven: Reuse tests in other Modules

Categories: Development Notes; Tagged with: ; @ September 6th, 2013 0:13


Reuse testcase in other Modules.

In ‘Module A’, I want to reuse the testcases in ‘Module-Core’ (e.g. extend Module-Core…AbstractUserManagerTest)

Solution: using attached test


Maven hello world

Categories: Java; Tagged with: ; @ July 21st, 2013 11:45

Use maven to create, test, build project.


  1. Create new project:
    mvn archetype:generate -DgroupId=com.liguoliang.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
  2. init Eclipse project:
    mvn eclipse:eclipse
  3. import the project into eclipse. (or you can directly create maven project in Eclipse using the Eclipse maven plugin)
  4. build the package:
    mvn package


life cycle:

  • validate: validate the project is correct and all necessary information is available
  • compile: compile the source code of the project
  • test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package: take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run
  • verify: run any checks to verify the package is valid and meets quality criteria
  • install: install the package into the local repository, for use as a dependency in other projects locally
  • deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

Trouble shooting

Error: Caused by: java.lang.UnsupportedClassVersionError:Unsupported major.minor version 51.0

Check the JVM which is using by Maven:

mvn –version can get a summary:

C:\Users\Guoliang>mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 16:44:56+0800)
Maven home: C:\Tools\sts\apache-maven-3.0.4\bin\..
Java version: 1.7.0_17, vendor: Oracle Corporation
Java home: C:\Tools\jdk7\jre
Default locale: en_SG, platform encoding: GBK
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

You can edit the Java Home path or specify the JVM for maven.

Maven: modify the default JDK 修改Maven默认JDK

Categories: Development Notes; Tagged with: ; @ May 1st, 2013 11:18

I created a maven java project, and I want to use some new feature in Java7, but every time, after update the project, the JRE will be changed to 1.5 automatically.

After googling, got the solution: configure maven-compiler-plugin:




// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.