| Author |
MySQL, JNDI refactoring
|
Zein Nunna
Ranch Hand
Joined: Mar 31, 2005
Posts: 245
|
|
Hi guys, I'm trying to engineer my web application. Hence any repeating code I'm trying to filter out. My database code I have filtered out to a different class, which can then be invoked as and when the application needs to connect the database. This throws an exception (Nullpointer... at line - this also throws a class cast exception ) Now I'm guessing this is because the class is being invoked by another class, and hence no context is passed? How do I get round this? Any ideas? Should I use a different methodology of refactoring my code? Regards Zein
|
 |
Herman Schelti
Ranch Hand
Joined: Jul 17, 2006
Posts: 387
|
|
hi Zein, your code looks fine to me. But what do you mean by "This throws an exception (Nullpointer... at line - this also throws a class cast exception )" ??? You can not cause a NullPointerException and a ClassCastException in 1 line in 1 run. Show us somelines of the stacktrace of your exception. Herman
|
 |
Zein Nunna
Ranch Hand
Joined: Mar 31, 2005
Posts: 245
|
|
Right guys igonore this problem. Ive got to the bottom of it. I divided the DB connection code soo the connection/lookup is done by one method, and the execute query is done another method. The reasoning behind this was you have 2 methods executeUpdate, and executeQuery in java hence this part would have been handled by different methods. This approach didnt work. I've now put in some extra if/else statments and I do the whole connection/lookup/ execution of query in one method. It works fine. Thanks anyway for looking into it. Regards Zein [ March 07, 2007: Message edited by: Zein Nunna ] [ March 07, 2007: Message edited by: Zein Nunna ]
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26489
|
|
|
Thanks for posting the solution so that others who see this thread in the future can benefit.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: MySQL, JNDI refactoring
|
|
|