Archive for August, 2010

h1

Character encoding issues with MySQL and JAVA

August 12, 2010

I had an interesting (annoying) bug with one of my Java applications today. Using the MySQLConnector I was reading a record out of a table, then re-inserting it with a few fields changed. One of the untouched fields was a piece of text into which a user had used a non-standard character (a greek sigma σ). The JAVA appeared to read the original record fine and would print it out correctly to the terminal. However, writing it back the db caused it to be converted into a question mark (?). Tracked the problem down to the MySQL driver not being able to determine the character set of the database and making a guess which was wrong. You can specify the character set in the connection string like this though which fixes the problem:

jdbc:mysql://host/dbname?characterEncoding=utf8

There is a whole list of cool flags you can put on the end of the connection string listed here:
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.htm

My other favourite is profileSQL=true which prints all the statements sent to the MySQL db to the terminal.

h1

gvim in eclipse

August 12, 2010

I spent the morning trying to get eclipse work like vim. Here are the tweaks I had to do to get it almost like how I like it. These instructions are good for Ubuntu 10.04, they may differ on other platforms.

1. Make the package explorer open on a key press.
Minimise the package explorer window so its not eating up the screen. You can bring it back pressing SHIFT-ALT-Q then P. This setting is hidden in the Windows->preferences->General->Keys->Show View (View: Package … area. To minimise the package explorer window without the mouse, press ESC.

2. Make files open using gvim instead of the usual eclipse editor
Install gvim (sudo apt-get install gvim)
Then in eclipse: Windows->preferences->General->Editors->File Associations
Add each file type you need to open with gvim (e.g. *.java) and in the associated editors make Vim the default.

3. Make the vim editor look nice
The default colour scheme is awful. I had to add the following items to my ~/.gvimrc file

syntax on
colorscheme slate
:set guioptions-=T "Remove toolbar
:set guioptions-=m "Remove the menu bar
:set clipboard=unnamed

The clipboard option allows yank and paste between eclipse windows which didnt work without it.

And thats about it