Sunday, October 7, 2007

Executing SQL scripts on MYSQL

OK, this one IS in the manual :)

But nonetheless, why not take a shortcut & just google it :)

Anyhoo, let's assume you have a database called MYDB at machine localhost which you can access under user name web with password password. The file you want to execute is called sql_script.sql which contains SQL commands delimited by ; as shown below.

DROP TABLE IF EXISTS general_detail;
DROP TABLE IF EXISTS general;

Here's how you can execute this script on MySQL 5.0 :

mysql MYDB -h localhost -u web -ppassword < sql_script.sql

BTW, if you want to execute an SQL command quickly via the command line, type :

mysql MYDB -h localhost -u web -ppassword -e "alter table general AUTO_INCREMENT = 1"


"Exception creating identity" error for JBoss 4.2.1 in Linux

Recently when trying to run JBoss on PCLinuxOS, I keep getting the "Exception creating identity" error which terminates JBoss immediately. While suspecting the fact that there is no DNS server running in my LAN could be the culprit, I couldn't figure out how and where to solve this.

So I tried a somewhat hack-ish solution : the /etc/hosts file. It's been a while since I edit one of these. Anyway the hack was to add the name of the identity which JBoss said it can't refer to, meaning if JBoss' log says the following :


Exception creating identity dhcpp01


Then edit your /etc/hosts file as follows :


127.0.0.1 localhost dhcppc1


From herein, JBoss will start normally.

Thursday, September 6, 2007

RIM caught pants down


Got the above at RIM's Blackberry 8820 site today when I mistakenly add a dot after the "com" in the URL. Funny :)

its .... fat ?


ok, a little off topic but I can't help it ...

to me this feels like bumping into an old friend who is popular & attractive at high school only now he/she has ballooned up considerably. then there's the subsequent awkward conversation where I'll struggle hard not to comment on the weight issue.

man ... does it have to be this .... ugly ? why ?

Wednesday, August 8, 2007

The JNI UnsatisfiedLinkerError saga

Ever try to debug something where the solutions you found on the net does not seem to work in you machine ? Well I had one today.

Its actually related to the rather infamous UnsatisfiedLinkerError when running JNI related applications. My test code compiles OK & the DLL was built successfully. Nonetheless at runtime, said error always pops up.

I tried in vain at numerous compilation options as suggested on forums I found on the net but to no avail ... until I noticed this:




The UnsatisfiedLinkerError actually came from the line:


JNIEXPORT void JNICALL Java_ArrayHandler_returnArray


But since the ArrayHandler is actually in a package called org.semi, an UnsatisfiedLinkerError will arise at runtime. The correct signature would be as follows:


JNIEXPORT void JNICALL Java_org_semi_ArrayHandler_returnArray



Had a great laugh after I discovered this. There goes one day debugging something which should be obvious all along :)

The sample code I did can be downloaded at rapidshare, well, if they haven't deleted it yet :)

Microsoft Word tips

I found these on the net & decided to post some which will likely be used by yours truly. Hope you'll find them useful yourself.

Go to the position when you last closed the document
Shift + F5

Single line spacing
Ctrl + 1

Double line spacing
Ctrl + 2

1.5 line spacing
Ctrl + 5

Delete the current word under the cursor
Ctrl + Delete

Move a paragraph block
At any position in the paragraph, Shift + Alt then Up or Down arrow

Select content from current cursor position to the end of the current paragraph
Ctrl + Shift + Down Arrow

Monday, August 6, 2007

The mysterious "nextToken" smslib hack

The following hack was made to ATHandler.java in smslib for Java v3.0.2 (Beta)distribution in order to send SMS from a Java SE PC desktop application using the GSM modem feature on a mobile phone (E65, N95 or P990i) connected to the PC via Bluetooth.



I actually remarked the 2 highlighted lines as these were the source of a vague error when I ran JUnit tests in Eclipse. While I'm not exactly sure what I "fixed" (if you can call it that), said error disappeared and the SMS went through. Wohoo !! :D

FYI, the code I used was actually derived directly from the examples given with smslib but funny enough it took the hack above to get them working on all those 3 phones I tested.

Using FitLibrary with Patang

Recently I had to do a user acceptance test a.k.a. UAT, which involves testing a set of EJB3 beans running in JBoss 4.2.0.GA.

Decided to go for FitNesse & Patang combo, but to my horror Patang by default works with Fit as oppose to FitLibrary. The tests I'm running relies on special fixtures & features available only in FitLibrary.

After scouring through Patang's source code, I quickly locate the line where Patang calls Fit. Its actually inside FitServerRunner in method run. I changed the following line

   
FitServer fitServer = new FitServer();


to this:

   
FitServerBridge fitServer = new FitLibraryServer();


Then after rebuilding the Patang jars, I followed exactly the instructions as laid out in Patang's simple but effective manual. In no time, I was able to execute my UAT which utilises my deployed EJB3 beans in JBoss. Neat.

Now the hard part : coaching the QA team how to do modify a FitNesse WiKi. Sigh ....

BTW, the full source code for my modified FitServerRunner is shown below.

// START : code

package fitnesse.server;

import fit.Counts;
import fit.FitServer;
import fit.FitServerBridge;
import fitlibrary.suite.FitLibraryServer;

class FitServerRunner extends Runner {

public FitServerRunner(Parameters fitServerParameters) {
this.parameters = fitServerParameters;
}

protected Counts run(String[] params) throws Exception {
// FitServer fitServer = new FitServer();
FitServerBridge fitServer = new FitLibraryServer();

fitServer.run(params);
return fitServer.getCounts();
}

}

// END : code