Exceptions while working with Type 4; No exception with working with Type 2 driver

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

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?

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?

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

posted Nov 26, 2007 05:34:00

0

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

posted Nov 26, 2007 05:34:00

0

And a stacktrace of the exception would be nice too...

Gabbar singh
Greenhorn

Joined: Nov 23, 2007
Posts: 11

posted Nov 26, 2007 05:50:00

0

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)