hello there, i got a working application (an online bookstore) which interacts with MS access database through javaservlets. now i wish to change the database to oracle XE,but i am having many doubts and can't tell what to do to fix it. first doubt is,do i need to put a system dsn in control panel like i did to the MS access database? note that i am using oracle.jdbc.driver.OracleDriver. second,is my code correct at all? i will paste here the code of the java Database class which connects to the oracle database,and the code for a java servlet which calls the java class to connect to Database. code of java class: (Database.java)
In the connect method, you print a stack trace if there is a problem, but then swallow the exception. This allows code to continue and makes it likely you will get a null pointer later on when the connection is null.
Do the logs have the stack trace? Also, which is like 36?
It is perfectly correct to use Class.forName to explicitly load the driver.
What you really need to do is to deal with the point which Jeanne made about swallowing exceptions. This is poor practice, you should at least print the stacktrace.
You are also returning null from the get method. This is the immediate cause of the problem. It is better to either rethrow SQLException after printing the stacktrace or to not handle the exception at all.
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
author & internet detective