cli for postgres in linux

If  your PostgreSQL server is not started, start it with the following command.

sudo service postgresql start

To getting started with postgreSQL, open your Terminal, and type:

username$ sudo su - postgres

Now you are logged into your vm with the postgres user. Then connect to template1 database using the postgresql’s psql client:

postgres ~$  psql template1
postgres ~$  template1=#

Note the # symbol, declaring that you are logged to the database as a Super User.

Once you are done and want to disconnect from the database using \q, and quit from postgres user using ctrl+d.

Using Psql client

Let’s see some useful commands of the psql tool. First of all: you can get some help just typing \?in your psql command line. To exit from the appearing screen, just press the q button.

To load and execute SQL statemens from file, you can use this syntax:

\i my/file/path.sql

Writing long lines of SQL code in the command line can be really hard to debug. Use the \i to run from file or use:


To edit the input buffer with an editor. If you usually don’t use editor from command line use nano – it’s the simplest. To check what relations your database contains, use


If you want more information about a particular relation, use

\d myfancytable

Have fun!

my eclipse shortcut

  1. alt + enter  : project property. 
  2. ctrl/cmd + M : Maximize window
  3. alt+shift+r : rename
  4. ctrl/cmd + shift + O : organize import(automatic, very useful)
  5. Ctrl/cmd + / :  Annotate 1 or more lines.
  6. ctrl/cmd + shift + F : format code
  7. Control + I: Indent

    Is your code looking like this at times?

    eclipse keyboard shortcuts

    Simply highlight the code portion that looks hard to read, press Ctrl + i to indent everything nicely.

    keyboard shortcuts eclipse

check out google code from eclipse subversion

In window->show view-> svn repository .

In that window, right click and select “New” from the drop down menu, then click “Repository Location…”, enter the google code https  url.

after authentication, look carefully on the structure.

Then in the project, right click and Team-> share project.

In the following window, make sure the path is exactly the same as that in the repository.  Otherwise error would pop up.

eclipse project前面红色感叹号

如果删除了某个build path里的jar的源文件而没有在build path里面删除,工程前面就会出现红色感叹号。后果是很严重的,连更新的java文件都不会编译更新。悲催……


PS: primefaces中datatable接受类型只能是List不能是Set。所以在ORM的时候用List比Set保险!

Converting a Java Project to a Dynamic Web Project in Eclipse

To convert a Java Project to a Web Project switch to or open the Resource Perspective of the project, in the root of the project. Open the .project file and make sure the builders and natures are present that are needed for a web project. See the example below, the name should be the name of your project, the most important nodes are the nature children in the natures node:

		<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>

Once you’ve updated the .project file you can close the file and right click and choose properties on the project. When the properties window opens click on Project Facets. The Facets grid is probably empty, click the Modify Project button. Check the Dynamic Web Module and Java Facets, choose the Java and Servlet version that applies to your project. Click Next and specify the existing or new location of your src and web content directories. Click Finish.

As a final step I would recommend modifying the build path to compile your source directly into your /WEB-INF/classes directory by selecting Java Build Path and modifying the Default output directory.

arguments and VM arguments in Eclipse

Eclipse allows you to enter Program arguments and VM arguments into a Debug configuration. I have a Debug configuration for my ArgsTest class, and I pass in “pro1 pro2 pro3” as Program arguments and “-DsysProp1=sp1 -DsysProp2=sp2” as VM arguments.

Program arguments are arguments that are passed to your application, which are accessible via the “args” String array parameter of your main method. VM arguments are arguments such as System properties that are passed to the Java interpreter. The Debug configuration above is essentially equivalent to:

java -DsysProp1=sp1 -DsysProp2=sp2 test.ArgsTest pro1 pro2 pro3