Monday, December 29, 2008
Problem with date format in JDBC session
Issue:
Say there’s a stored procedure in Oracle named test_date which uses a variable of type DATE. The variable is not returned to java but simply used elsewhere in the procedure.
If I execute this procedure in oracle and check the date format, I see it’s using the format dd-mon-yyyy
If I execute this procedure over jdbc, the format I see is mm-dd-yyyy
This makes me believe that the date format used throughout the session is defined by the client (oracle vs. jdbc).
Fix:
Simple way to fix this is to alter the session at runtime and explicitly define the format used throughout the session
alter session set nls_date_format=''DD-MON-YYYY''
Friday, December 5, 2008
Good coding practices I use

- Write flexible code that can be changed and extended, changes in underlying technologies shouldn't ripple through the whole system
- Code should be maintainability – long shelf life
- Layers should not be tightly coupled. Each layer needs to be independent from the other. Use interfaces, dependency injection etc
- Indent all files using spaces (Indent once = 4 spaces)
- If you are using an IDE, use the formatter and tools that comes with it to organize and clean up your code
- Comment your code often. Use Javadoc standards.
- Use sensible naming conventions for variable, method and class names.
- Use exceptions only if required. Do not use exceptions to handle errors. If errors occur we want the message to propagated up the call stack.
- Do not use scriplets in your JSP code. Use JSTL Expression Languages where required.
- All jsp file names should be in lowercase
- All text in JSP's should either come from Database or Resource bundles. No text should be hard coded in HTML
- HTML pages should be XHTML Transitional
- Validate your HTML pages using w3c validators
- All styles should be written in css. No HTML style attributes
- If your code causes warnings or errors in other code, fix other code as well. There shouldn't be any code in CVS which has errors or warnings.
Tuesday, January 15, 2008
Unix file compression utilities
Friday, January 11, 2008
vi Commands
Undo Command
u undo the last command.
Screen Commands
CTL/F Pages forward one screen.
CTL/B Pages back one screen.
>> Indent right
<< Indent left
Cursor Positioning Commands
0 Moves cursor to beginning of current line.
$ Moves cursor to end of current line.
nG Moves cursor to beginning of line n. Default is last line of file.
:n Moves cursor to beginning of line n.
/pattern Moves cursor forward to next occurrence of pattern.
?pattern Moves cursor backward to next occurrence of pattern.
n Repeats last / or ? pattern search.
N Repeats last / or ? pattern search in opposite direction
:.= Print line number of current line
Text Insertion Commands
a Appends text after cursor.
A Appends text at the end of the line.
i Inserts text before cursor.
I Inserts text at the beginning of the line.
Text Deletion Commands
x Deletes current character.
dd Deletes current line.
d) Deletes the rest of the current sentence.
D, d$ Deletes from cursor to end of line.
P Puts back text from the previous delete.
Changing Commands
~ Changes case of current character.
J Joins current line with next line.
Cut and Paste Commands
yy Puts the current line in a buffer. Does not delete the line from its current position.
p Places the line in the buffer after the current position of the cursor.
Appending Files into Current File
:R filename Inserts the file filename where the cursor was.
Exiting vi
ZZ Exits vi and saves changes.
:wq Writes changes to current file and quits edit session.
:q! Quits edit session (no changes made).
Visual mode commands
v Start/stop visual mode Allows you to select a block of text
> shift the block right one shiftwidth
< shift the block left one shiftwidth
y yank ( copy ) the block ( paste with a p )
d delete the block
c change the block