tomcat 5.5 mysql 连接池

jsp 倒很容易配出来。conf/context.xml

<Resource
         name="jdbc/person"
         type="javax.sql.DataSource"
         password="root"
         driverClassName="com.mysql.jdbc.Driver"
         maxIdle="2"
         maxWait="5000"
         username="root"
         url="jdbc:mysql://localhost:3306/person"
         maxActive="4"/>    

然后直接用就可以了。

但封装到java 里我到现在没搞出来,不知道是什么原因。

错误提示。

 

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.BasicDataSource cannot be cast to sun.jdbc.odbc.ee.DataSource
	rubicon.ConnDB.getConn(ConnDB.java:23)
	rubicon.BeanCl.getResultByPage(BeanCl.java:23)
	rubicon.Wel.doPost(Wel.java:42)
	rubicon.Wel.doGet(Wel.java:18)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

 

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.28 logs.


 

 

public Connection getConn(){

 
   try {
    Context ctx=new InitialContext();
       DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/person");  
       conn = ds.getConnection();
   } catch (NamingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }   
  
  return conn;
    
    
 /* String url = "jdbc:mysql://localhost:3306/person";
  
  try {
   Class.forName("com.mysql.jdbc.Driver");
   conn=DriverManager.getConnection(url,"root","root");
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   System.out.println("无法加载驱动程序");
  }catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   System.out.println("无法连接驱动程序");
  }
  return conn;*/

 }

我用绿色文字(注释)的就成功,用上面这段就不成功。苦恼啊。这个问题我先放着,留着以后解决。路过的朋友也帮忙看看。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值