| Author |
Exceptions while working with Type 4; No exception with working with Type 2 driver
|
Gabbar singh
Greenhorn
Joined: Nov 23, 2007
Posts: 11
|
|
Hi - I am using WSAD 512, JDk 1.4 and DB2 7. My code (includes add/edit/delete database operations) works fine with WSAD 512 and Type 2 driver. However when i migrate the code to RAD with the same settings and Type 4 driver , i frequently get NP exceptions. We use statements like preparedStatement.setString to set values for Number fields in the DB. This works fine with WSAD. Does this work fine with Type 4 driver also Any comments will be appreciated
|
 |
Herman Schelti
Ranch Hand
Joined: Jul 17, 2006
Posts: 387
|
|
hi Gabbar, do we have to guess where these NullPointerExceptions occur? Herman
|
 |
Gabbar singh
Greenhorn
Joined: Nov 23, 2007
Posts: 11
|
|
Herman - Heres the info I use prepared stament to perform operations on the DB (Db2 ver 7.0). I use a setString method to set value to an INT field in the DB . This works fine with my WSAD env. (I use type 2 driver). However when i run the same code in RAD env, which uses a type 4 driver, it crashes with exceptions. My question is do Type 2 and Type 4 drivers behave differently with the same portion of code? I also came across this link http://www.coderanch.com/t/301727/JDBC/java/Type-Type-Drivers-DB which makes me think so Thanks for your help
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
So the NPE occurs in the call to setString on the PreparedStatement? Or does it occur somewhere else? How do you create your statement? Can you post your code?
My question is do Type 2 and Type 4 drivers behave differently with the same portion of code?
They may well be implemented differently, but the result of the code should be the same. If it weren't I'd say it was a bug in the driver. The post you link to is about date formatting - it is unlikely to be the same problem, unless you too are treating a Date as a String?
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Gabbar singh
Greenhorn
Joined: Nov 23, 2007
Posts: 11
|
|
The NPE occurs while a transaction (add/update/delete) is executed. The code snippet is preparedStatement.setString(1, testBean.getTotalPages()); Now the Pages column is an Integer in the DB - so basically this is setting a string in an Integer field in the DB (though the screen validates and forces the user to enter only numbers) The strange thing is it works with Type 2 driver, but crashes with Type 4.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Now the Pages column is an Integer in the DB - so basically this is setting a string in an Integer field in the DB (though the screen validates and forces the user to enter only numbers)
Sounds like what you are doing is invalid. Perhaps the type 2 driver does conversion from a text to numeric data for you and the type 4 doesn't? Does it work if you call setInt() instead? That being the case, I'd expect there to be a SQLException if a required value is not being set. A NPE suggests something in your code is null. Can you post your code?
|
 |
Gabbar singh
Greenhorn
Joined: Nov 23, 2007
Posts: 11
|
|
Thanks Paul. Yes it is invalid. My question was - does IBM Type 2 Db2 driver perform an implict conversion from string to number? I mean is it how it works and has IBM stated so Regarding the exception, the term NPE was used by the end user without actually seeing the log - so in reality it could have been a database exception
|
 |
Herman Schelti
Ranch Hand
Joined: Jul 17, 2006
Posts: 387
|
|
|
And a stacktrace of the exception would be nice too...
|
 |
Gabbar singh
Greenhorn
Joined: Nov 23, 2007
Posts: 11
|
|
java.lang.NullPointerException at com.xyz.dao.SearchDAO.searchs(SearchDAO.java:71) at com.xyz.blo.SearchBLO.searchs(SearchBLO.java:98) at com.xyz.conversation.SearchConversation.search_xa(SearchConversation.java:218) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code)) at java.lang.reflect.Method.invoke(Method.java(Compiled Code)) at javax.servlet.http.HttpServlet.service(HttpServlet.java:763) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1282) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:673) at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2905) at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220) at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204) at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1829) at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:84) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:472) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:411) at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:101) at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:566) at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:619) at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:952) at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1039) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1455)
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Seems like the NPE stops in your code, and is NOT thrown by the drivers. You're saying it is this line: That leaves two possibilities: 1) preparedStatement is null 2) testBean is null If preparedStatement.setString or testBean.getTotalPages was throwing the NPE it would have shown up in the stack trace, so you have to check out your own code. Are you sure neither is null?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Exceptions while working with Type 4; No exception with working with Type 2 driver
|
|
|