Sunday, August 11, 2013

generic .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Friday, July 5, 2013

URI is not hierarchical - Java

There are some problems when running the build jar of your project compare to running it in an IDE, when resources such as images is called within the build jar, usually we just use getClass#getResource("path/of/the/image.jpg") in the IDE, and when you build the project and execute the jar the "URI is not hierarchical" is thrown. One way to fix this is retrieve it as a resource-stream like.

InputStream dx = this.getClass().getResourceAsStream("/com/sample/images/default_image.png");
Image sm = ImageIO.read(dx).getScaledInstance(width, height, Image.SCALE_SMOOTH);

You can then us the Image in any component.

Wednesday, May 8, 2013

Enable localhost phpmyadmin to login

Set the config.php under phpmyadmin folder to this


Catch ConstraintViolationException in Hibernate and get the Error message

I am developing a Java desktop app and I'm using Hibernate on it. In the documentation of Session#save() it only returns Serializable and I have to get a response object when it throws an exception during save call. Heres what I did.

I enclose it with a try catch, and when it receives an exception just get the ConstraintViolationException#getMessage(1) object of it. You can directly return the Object or encapsulate it with your custom object.