你试试这是我写的连接mysql的tomcat的javabean
package com.cf;
//定义Bean所属的套件import java.io.*;
import java.sql.*;//定义DBCon类型实做HttpSessionBindingListener接口
public class DBCon
{
 //与数据库链接有关的Bean属性
 private Connection con=null;
 private Statement stmt=null;
 private ResultSet rs=null;
 String ConStr="jdbc:mysql://localhost:3306/hotweb?user=admin&password=admin";public Connection getConnection() throws Exception      //连接数据库的方法
{
   try{
       Class.forName("org.gjt.mm.mysql.Driver");
       if(con==null){
       con=DriverManager.getConnection(ConStr);
       }
      }
   catch(ClassNotFoundException classnotfoundexception)
      {
       System.err.println("DBconn (): " + classnotfoundexception.getMessage());
      }
   return this.con;
 }
//查询数据库
public  ResultSet query(Connection con,String sql)
  { 
   
   try{
      this.con=con;
      stmt=this.con.createStatement();      rs=stmt.executeQuery(sql);
      
     
     }
   catch(SQLException sex)
     {
          System.out.println(sex.toString());
     }
   return this.rs;
  }
  
//更新数据库(包括插入,修改,删除)
public void update(Connection con,String strsql)
  {
     
  try{
      //this.con=con;
      stmt=con.createStatement();      stmt.executeUpdate(strsql);
      
     
     }
  catch(SQLException sex)
     {
          System.out.println(sex.toString());
     }
    
  }
  //关闭连接!
public void close()
{
  try{
      con.close();
      con=null;
     } 
  catch(Exception sex)
     {
      System.out.println(sex.toString());
     } 
}}    
其中数据库的用户名和密码均为admin,你可以该成你自己的用户名和密码

解决方案 »

  1.   

    忘了说一声,将驱动程序放在根目录的lib下面,再将该路径放至于classpath下
    如:E:\My Webs\Tomcat 4.1\common\lib\mysqldriver.jar
      

  2.   

    谢谢!!那mm.mysql.jdbc-1.2c应该放在Resin3.x 的那啊?
      

  3.   

    其实mm.mysql.jdbc-1.2c放在哪里无所谓,关键是要将其加入系统的classpath中去,这样java虚拟机才知道你调用的类