Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySQL, JNDI refactoring

 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 35266
383
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting the solution so that others who see this thread in the future can benefit.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic