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 ??