Monday, December 29, 2008

Problem with date format in JDBC session

The other day I came across this issue and spent some time figuring out what was going on. Hope it can help someone.

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



  1. Write flexible code that can be changed and extended, changes in underlying technologies shouldn't ripple through the whole system

  2. Code should be maintainability – long shelf life

  3. Layers should not be tightly coupled. Each layer needs to be independent from the other. Use interfaces, dependency injection etc

  4. Indent all files using spaces (Indent once = 4 spaces)

  5. If you are using an IDE, use the formatter and tools that comes with it to organize and clean up your code

  6. Comment your code often. Use Javadoc standards.

  7. Use sensible naming conventions for variable, method and class names.

  8. 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.

  9. Do not use scriplets in your JSP code. Use JSTL Expression Languages where required.

  10. All jsp file names should be in lowercase

  11. All text in JSP's should either come from Database or Resource bundles. No text should be hard coded in HTML

  12. HTML pages should be XHTML Transitional

  13. Validate your HTML pages using w3c validators

  14. All styles should be written in css. No HTML style attributes

  15. 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.