MySQL exception of DATETIME value in JSP

There is a column type DATETIME and default value as “0000-00-00 00:00:00″ in MySQL. When Using JSP with JDBC query and get result via getString, there arise an error:

java.sql.SQLException: Value ’0000-00-00 ‘ can not be represented as java.sql.Timestamp

As far as I see, this is a new feature of JDBC since version 3.1. However I did not encounter (or I ignore) it for a long time.

The value of MySQL is not valid in JAVA and the solution is to add a parameter in connection. Reference is here: Driver/Datasource Class Names, URL Syntax and Configuration Properties for Connector/J

That is, add zeroDateTimeBehavior=convertToNull into JDBC connection. and it works. 🙂

Install java-7-oracle with PPA on Ubuntu

This note is based on Howto- Install Oracle Java7 in Ubuntu12.04 Precise Pangolin | PPA. The download procedure in oracle-java7-installer package is broken. We should modify it for the rest automatically installation. The summary of my steps are listing:

1. Purge installed JDKs:
# apt-get purge openjdk* sun-java6*

2. Add repository for installation:

1
2
# add-apt-repository ppa:eugenesan/java
# apt-get update

3. Modify the installation procedure:
# vim /var/lib/dpkg/info/oracle-java7-installer.postinst
Comment out lines 103-106 which refers to download JDK. The contents may seems like:

rm -f $FILENAME
WGETRC=wgetrc wget $PARTNER_URL \
|| fp_exit_with_error “download failed”
rm -f wgetrc

4. Manual download JDK source and move it into installation directory:
# mv {source} /var/cache/oracle-java7-installer/
The type (x86/x64) and name of the source can be found within the directory (if you had try to install). Eg: jdk-7u3-linux-x64.tar.gz.

5. Resume the installation:
# apt-get install oracle-java7-installer
All things done. Happy enjoy. 🙂