DB Connection prob 2007-03-20 - By Richard Yee
Back Graeme, Since you mention that you are using a deployment descriptor, I am assuming this is for a web application. If this is so, your application is not going to be thread-safe b/c the connection is static and can be used by different threads. If this is for a web application, you should use a connection pool and a datasource. In your current problem, your variables should not be final.
-Richard
Graeme McLaren wrote: > Hi all, I have a prob connecting to my Oracle DB. I have a class called > "DBConnection" and have various setter methods which set values found > in the > deployment descriptor, for example: > > public static void setDriver (String val) { > driver = val; > System.out.println("driver 2= "+driver); // I get the value > displayed here so all is good at this point > } > > I then have a getConnection method within this class: > > public static Connection getConnection(){ > try{ > Class.forName( driver ); // load the JDBC "driver" class > connection = DriverManager.getConnection( dbURL, username, > password ); > // get connection > > /* > more code here > */ > > } // end of getConnection > > > > When I try to call getConnection() I get a nullpointerexception at > Class.forName( driver ); as "driver" is set to null, why is this when the > setter method sets the value? > > All variables are declared set to null and are static so they should > be able > to be set by the setter method shouldn't they? Just thinking about it > now > I'm thinking that when the variables are initialised to "null" that is > them > set and cannot be changed because they are static (and final), would > that be > right? > > How should I fix this? > > > Cheers > > Graeme :) > > =========================================================================== > > To unsubscribe: mailto listserv@(protected) with body: "signoff > JSP-INTEREST". > For digest: mailto listserv@(protected) with body: "set JSP-INTEREST > DIGEST". > > Some relevant archives, FAQs and Forums on JSPs can be found at: > > http://java.sun.com/products/jsp > http://archives.java.sun.com/jsp-interest.html > http://forums.java.sun.com > http://www.jspinsider.com > >
=========================================================================== To unsubscribe: mailto listserv@(protected) with body: "signoff JSP-INTEREST". For digest: mailto listserv@(protected) with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
|
|