Topic: 急,急,急!在linux上用servlet连接DB2出了很奇怪的问题(no suitable driver)

  Print this page

1.急,急,急!在linux上用servlet连接DB2出了很奇怪的问题(no suitable driver) Copy to clipboard
Posted by: luckymlj
Posted on: 2003-10-27 16:39

各位大侠,救救小弟!
我在linux(suse)下写了一个很简单的数据库连接测试代码,web server是Tomcat4.1.24,数据库是IBM DB2 8.1
代码如下:
import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;

import javax.sql.*;

/**
* @version   1.0
* @author Jason
*/
public class Test extends HttpServlet implements Servlet {
  
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
      String strDriver="COM.ibm.db2.jdbc.app.DB2Driver";
      String strUrl="jdbc:db2:susedb1";
      String user="Jason";
      String passwd="Jason";
      try {
        Class.forName(strDriver);
        Connection conn=DriverManager.getConnection(strUrl,user,passwd);
        String sql="select * from cxpbusobjstate";
        Statement stat=conn.prepareStatement(sql);
        
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        resp.sendRedirect("error.jsp");
        return;
      }
      resp.sendRedirect("success.jsp");
      System.out.println("It's over!");

  }
  public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
      doGet(req,resp);
  }
}
然后,我用了一个名为login.jsp的简单页面来调用这个servlet,我的意思是希望成功的时候返回一个success.jsp的页面,失败的时候返回一个error.jsp的页面,但是这个简单的程序在windows2000的tomcat上运行良好,但是在linux(Suse)上就抛出了no suitable driver的错误。
小弟已经将db2 的db2java.zip包指定到了catalina.sh文件中,并确保其工作了,应为如果没有指定该文件,报出的异常是找不到driver,而不是no suitable driver,请各位大侠多多帮忙,不胜感激!
如果上面问题写得不够清楚,请大家指正,小弟聆听指教!

多谢!!!!!

2.Re:急,急,急!在linux上用servlet连接DB2出了很奇怪的问题(no suitable driver) [Re: luckymlj] Copy to clipboard
Posted by: why
Posted on: 2003-10-27 21:11

Are you using the db2java.zip that comes with DB2 8.1 that you're connecting to?
db2java.zip may be different across different servers & clients.

I would use DB2 8.1's Type 4 driver -- db2jcc*.jar Smile

3.Re:急,急,急!在linux上用servlet连接DB2出了很奇怪的问题(no suitable driver) [Re: luckymlj] Copy to clipboard
Posted by: luckymlj
Posted on: 2003-10-29 09:06

hehe, I have done it, but it can not work correctly! Smile
At first, I think maybe the file version of db2java.zip is not correct, so I add this file path in catalina.sh. I am sure this file can work ok.
At last, I add LD_LIBRARY_PATH to the profile file, but Sad
So, now I don't know how can I make this servlet work?
If any suggestion, tell me!
Thank you and Best Regards

4.Re:急,急,急!在linux上用servlet连接DB2出了很奇怪的问题(no suitable driver) [Re: luckymlj] Copy to clipboard
Posted by: scottlai
Posted on: 2003-10-29 09:11

1. 你CLIENT的DB2 JDBC DRIVER 版本跟SERVER不同(含FIXPACK LEVEL).
2. 如果你CLIENT有裝DB2 NATIVE RUNTIME. 那CLIENT 的NATIVE RUNTIME可能跟你JAR的版本不一樣.

SO.
1. 從SERVER COPY JAR回來用
2. CLIENT NATIVE RUNTIME如果跟SERVER 版本不一樣.那重裝CLIENT NATIVE RUNTIME.

5.Re:在linux上用servlet连接DB2出了很奇怪的问题 [Re: luckymlj] Copy to clipboard
Posted by: luckymlj
Posted on: 2003-10-29 16:16

Thank you all!
I ran the test class on the same machine with DB2, so, I think the db2java.zip file is right. But, when I porting this class to windows, it works ok. I think it's very strange!
At last, I transfer this file to a simple java class to test, the same error happened.
I don't think it is a big problem, because if it is do so like my case, DB2 is awful in linux, so I think there should be something I do not know.
Thank you for your help, and best wish for all of you!
If there is anything helpful to this problem, let me know.
My msn is luckymlj@hotmail.com
welcome to discuss with me about technology!
My Special is : java, DB, linux

6.DB2 no suitable driver问题 [Re: luckymlj] Copy to clipboard
Posted by: why
Posted on: 2003-10-29 21:10

forget about db2java.zip and client version mess
and try Type-4 db2jcc*.jar

7.Re:急,急,急! [Re: luckymlj] Copy to clipboard
Posted by: floater
Posted on: 2003-10-29 22:54

sigh*, it's in your code, check this line:

String strDriver="COM.ibm.db2.jdbc.app.DB2Driver";

8.Re:(no suitable driver) [Re: luckymlj] Copy to clipboard
Posted by: luckymlj
Posted on: 2003-10-30 17:53

Hi, floater, what do you think about that sentence. I think it is not wrong to DB2.
To why, I can not change the Driver now I used. But thank you for you suggestion.
Now, I solved this problem successfully.
The steps are:
run this command before start the App Server:
. /home/db2inst1/sqllib/db2profile
then start the app server to access that servlet, Smile everything is ok!

Last , Thank you all for your help

9.Re:(no suitable driver) [Re: luckymlj] Copy to clipboard
Posted by: nothing
Posted on: 2003-10-30 17:59

晕..

10.Re:急,急,急! [Re: luckymlj] Copy to clipboard
Posted by: why
Posted on: 2003-10-30 20:00

I have forgotten everything about DB2 since I just wrote 2 Cert tests.Smile

I guess floater was referring to the use of COM.ibm.db2.jdbc.net.DB2Driver
verus COM.ibm.db2.jdbc.app.DB2Driver

Q: Which DB2 JDBC driver should I use--the appplication driver or the net driver?

A: http://www-1.ibm.com/support/docview.wss?rs=0&q=1005576&uid=swg21005576

And check DB2 Application Development Guide for further information.Smile

11.Re:急,急,急! [Re: luckymlj] Copy to clipboard
Posted by: floater
Posted on: 2003-10-31 23:26

Coudl you post the content of the file
. /home/db2inst1/sqllib/db2profile
so we could see what's in there.

12.Re:在linux上用servlet连接DB2出了很奇怪的问题 [Re: luckymlj] Copy to clipboard
Posted by: luckymlj
Posted on: 2003-11-05 14:41

Ok, that's no problem!
But I think if you install DB2 on linux, there will be a file named db2profile on that path.
Any Way, I paste this file for all of you :)
=============================================
#
#############################################################################
#
# Licensed Materials - Property of IBM
#
# 5724-B62
# (C) COPYRIGHT International Business Machines Corp. 1993, 2002
#
# 5724-D54
# (C) COPYRIGHT International Business Machines Corp. 1993, 2002
#
# 5765-F35
# (C) COPYRIGHT International Business Machines Corp. 1993, 2002
#
# 5765-F43
# (C) COPYRIGHT International Business Machines Corp. 1993, 2002
#
# 5765-F41
# (C) COPYRIGHT International Business Machines Corp. 1993, 2002
#
# 5765-F30
# (C) COPYRIGHT International Business Machines Corp. 1993, 2002
#
# 5765-F34
# (C) COPYRIGHT International Business Machines Corp. 1993, 2002
#
# 5765-F31
# (C) COPYRIGHT International Business Machines Corp. 1993, 2002
#
# 5765-F42
# (C) COPYRIGHT International Business Machines Corp. 1993, 2002
#
# All Rights Reserved
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
#############################################################################
#
# NAME: db2profile
#
# FUNCTION: This script sets up a default database environment for
# Bourne shell or Korn shell users.
#
# USAGE: . db2profile
# This script can either be invoked directly as above or
# it can be added to the user's .profile file so that the
# database environment is established during login.
#
# #### DO NOT EDIT THIS FILE ####
#
#############################################################################

# Default DB2 product directory
DB2DIR="/usr/opt/db2_08_01"

# Function to avoid repetitive environment variable entries
AddtoString()
{
var=$1
addme=$2
awkval='$1 != "'${addme?}'"{print $0}'
newval=`eval /usr/bin/echo \\${$var} | /usr/bin/awk "${awkval?}" RS=:`
eval ${var?}=`/usr/bin/echo $newval | /usr/bin/sed 's/ /:/g'`:${addme?}
unset var addme awkval newval
}

#-----------------------------------------------------------------------
# DB2INSTANCE [Default null, values: Any valid instance name]
# Specifies the instance that is active by default.
#-----------------------------------------------------------------------
DB2INSTANCE=db2inst1
export DB2INSTANCE

INSTHOME=/home/db2inst1

#-----------------------------------------------------------------------
# First remove any sqllib entries from the user's path.
# Add the directories:
# INSTHOME/sqllib/bin - database executables
# INSTHOME/sqllib/adm - sysadm executables
# INSTHOME/sqllib/misc - miscellaneous utilities
# to the user's PATH.
#-----------------------------------------------------------------------

AddtoString PATH ${INSTHOME?}/sqllib/bin
AddtoString PATH ${INSTHOME?}/sqllib/adm
AddtoString PATH ${INSTHOME?}/sqllib/misc
export PATH

#-----------------------------------------------------------------------
# UDB Extender initialization
#-----------------------------------------------------------------------
if [ -f ${INSTHOME}/dmb/dmbprofile ]; then
. ${INSTHOME}/dmb/dmbprofile
fi

#-----------------------------------------------------------------------
# The following variables are used for JDBC support
#-----------------------------------------------------------------------
CLASSPATH=${CLASSPATH:-""}

if [ -f ${INSTHOME?}/sqllib/java/db2java.zip ]; then
AddtoString CLASSPATH ${INSTHOME?}/sqllib/java/db2java.zip
fi
if [ -f ${INSTHOME?}/sqllib/java/db2jcc.jar ]; then
AddtoString CLASSPATH ${INSTHOME?}/sqllib/java/db2jcc.jar
fi
if [ -f ${INSTHOME?}/sqllib/java/sqlj.zip ]; then
AddtoString CLASSPATH ${INSTHOME?}/sqllib/java/sqlj.zip
fi
if [ -d ${INSTHOME?}/sqllib/function ]; then
AddtoString CLASSPATH ${INSTHOME?}/sqllib/function
fi

if [ -f ${INSTHOME?}/sqllib/java/db2jcc_license_cisuz.jar ]; then
AddtoString CLASSPATH ${INSTHOME?}/sqllib/java/db2jcc_license_cisuz.jar
fi

if [ -f ${INSTHOME?}/sqllib/java/db2jcc_license_cu.jar ]; then
AddtoString CLASSPATH ${INSTHOME?}/sqllib/java/db2jcc_license_cu.jar
fi

AddtoString CLASSPATH .
export CLASSPATH

#-----------------------------------------------------------------------
# The following variables are used for Data Warehouse support
#-----------------------------------------------------------------------
if [ -d ${INSTHOME?}/sqllib/templates ]; then
VWS_TEMPLATES=${INSTHOME?}/sqllib/templates
export VWS_TEMPLATES
fi
if [ -d ${INSTHOME?}/sqllib/logging ]; then
VWS_LOGGING=${INSTHOME?}/sqllib/logging
export VWS_LOGGING
fi
VWSPATH=${INSTHOME?}/sqllib
export VWSPATH

LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-""}
AddtoString LD_LIBRARY_PATH ${INSTHOME}/sqllib/lib
export LD_LIBRARY_PATH

# If LIBPATH isn't set, AIX assumes "/usr/lib:lib". But if LIBPATH
# is set, AIX makes no such assumption. Thus, to duplicate AIX's
# behaviour, if LIBPATH is not set, add the assumptions, but if LIBPATH
# is already set, we must make the same assumption that /usr/lib:lib is
# already in the LIBPATH somewhere.

LIBPATH=${LIBPATH:-"/usr/lib:/lib"}
AddtoString LIBPATH ${INSTHOME}/sqllib/lib
export LIBPATH

# Any user changes to the environment goes into userprofile. Modifications
# to db2profile may be overwritten in fixpaks.
if [ -f ${INSTHOME?}/sqllib/userprofile ]
then
. ${INSTHOME?}/sqllib/userprofile
fi

EXTSHM=ON
export EXTSHM


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923