If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > CAN NOT produce preparedStatement with COM.ibm.db2.jdbc.net.DB2Driver

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-03-05, 06:18
javapollo javapollo is offline
Registered User
 
Join Date: Feb 2005
Posts: 2
CAN NOT produce preparedStatement with COM.ibm.db2.jdbc.net.DB2Driver

Hi everyone,

I'm using WebSphere 5.1.2 as application developer and DB2 8.1.7 UDB as DBMS. I develop a web application in struts environment. Everything's fine when I make Statement but I have a problem preparing statements with conn.prepareStatement(strQry). I've made a long research in Internet, found some solutions like "add db2jcc.jar, db2java.zip" to the classpath" for the same problem but I already have them in my classpath. Anyway, here's my settings and the information that I think neccessary. If you wonder any other settings in my comp. I'm ready to write them later.

In the WebSphere console it says :


[23.01.2005 15:06:33:438 EET] 231c4689 WebGroup E SRVE0026E: [Servlet Error]-[com/ibm/db2/jcc/SQLJPackage]: java.lang.NoClassDefFoundError: com/ibm/db2/jcc/SQLJPackage
at COM.ibm.db2.jdbc.net.DB2Connection.prepareStatemen t(Unknown Source)
at org.apache.commons.dbcp.DelegatingConnection.prepa reStatement(DelegatingConnection.java:185)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuar dConnectionWrapper.prepareStatement(PoolingDataSou rce.java:278)
at com.yildiz.mersam.actions.DosyaAction.processUploa dedFile(DosyaAction.java:195)
at com.yildiz.mersam.actions.DosyaAction.execute(Dosy aAction.java:83)
at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
at ...




and meanwhile on the browser it displays : Error 500: com/ibm/db2/jcc/SQLJPackage
(Note that com.ibm.db2.jcc.SQLJPackage class is in db2jcc.jar)


my classpath variables are :

.;
C:\PROGRA~1\IBM\SQLLIB\java\db2java.zip;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;
C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cisuz.j ar;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cu.jar;
C:\PROGRA~1\IBM\SQLLIB\bin;
C:\PROGRA~1\IBM\SQLLIB\tools\db2XTrigger.jar;
C:\PROGRA~1\IBM\SQLLIB\java\common.jar;
C:\j2sdk1.4.2_03\lib




and I have all the necessary jars, zips in WEB-INF/lib directory(At least I have no problems in making raw Statement queries).


Here's my data-source settings in struts-config.xml :


<data-sources>
<data-source key="mersam" type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="url" value="jdbc:db2://127.0.0.1:6789/MERSAM"/>
<set-property property="username" value="user"/>
<set-property property="password" value="pass"/>
<set-property property="driverClassName" value="COM.ibm.db2.jdbc.net.DB2Driver"/>
</data-source>
</data-sources>


The actual method accessing the DB in Action class is as follows :


private int processUploadedFile(FileItem item) {
Connection conn = null;
PreparedStatement prestmt = null;
int result = -1;
String strQry = null;
ServletContext servletContext = servlet.getServletContext();

// request is globally defined in Class
DataSource dataSource = getDataSource(request, "mersam");

String fieldName = item.getFieldName();
String fileName = item.getName();
String contentType = item.getContentType();

InputStream is = item.getInputStream();

...
...

try {

conn = dataSource.getConnection();
strQry = "INSERT INTO MERSAM.DOSYALAR(dosya, file_name) " +
"VALUES(?, ?)";

prestmt = conn.prepareStatement(strQry);
prestmt.setBinaryStream(1, is, (int)size);
prestmt.setString(2, fileName);
result = prestmt.executeUpdate();

prestmt.close();
} catch (SQLException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}

return result;
}

////////////////////////////////////////////////////////////////////////////////

In some forums, "COM.ibm.db2.jdbc.net.DB2Driver" in db2java.zip is said to be unsupported driver for preparedStatements. OK, but what is the alternative ??
Reply With Quote
  #2 (permalink)  
Old 02-03-05, 13:35
akratz akratz is offline
Registered User
 
Join Date: Aug 2002
Posts: 76
driver

Try COM.ibm.db2.jdbc.app.DB2Driver
We use it for prepared statements on both 7.2 and 8.2

I believe it is also in db2java.zip so your classpath should be fine
Reply With Quote
  #3 (permalink)  
Old 02-03-05, 16:39
javapollo javapollo is offline
Registered User
 
Join Date: Feb 2005
Posts: 2
Re:

I think that the main problem is
java.lang.NoClassDefFoundError: com/ibm/db2/jcc/SQLJPackage
However this class is already included in db2jcc.jar !!
Anyway, I've tried COM.ibm.db2.jdbc.app.DB2Driver but it gives the same problem. May it be concerned with the classpath settings ??
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On