首页 新闻 会员 周边 捐助

用c3p0连接池和Dbutils连接数据库做了一个银行转账案例一直报500错误,在线求大佬指教,困扰已久

0
[待解决问题]

错误:
HTTP Status 500 - Servlet execution threw an exception

type Exception report

message Servlet execution threw an exception

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

exception

javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/ComboPooledDataSource
utils.DateSourceUtils.<clinit>(DateSourceUtils.java:13)
severce.TransferService.Transfer(TransferService.java:25)
web.Transfer.doGet(Transfer.java:32)
web.Transfer.doPost(Transfer.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
utils.DateSourceUtils.<clinit>(DateSourceUtils.java:13)
severce.TransferService.Transfer(TransferService.java:25)
web.Transfer.doGet(Transfer.java:32)
web.Transfer.doPost(Transfer.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

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

jsp表单提交
<body>
<form action="Transfer" method="post">
请输入您的用户:<input type="text" name="outname"><br>
请输您要转的用户:<input type="text" name="inname"><br>
请输入您的转账金额:<input type="text" name="money"><br>
<input type="submit" value="确认转账">
</form>
</body>
在web层servlet代码
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String inname=request.getParameter("inname");
String outname=request.getParameter("outname");
String moneystr=request.getParameter("money");
double money=Double.parseDouble(moneystr);
TransferService Service=new TransferService();

        boolean cs=Service.Transfer(inname,outname,money);
        if(cs){
        response.getWriter().write("转账成功");
        System.out.println("转账成功");
        }else{
            response.getWriter().write("转账失败!!!");
            System.out.println("转账失败");
        }
        
}

在service层代码
public class TransferService {

public boolean Transfer(String inname, String outname, double money)  {
    Transferdao dao=new Transferdao();
    boolean cs=true;
    try {
        Connection conn=DateSourceUtils.getConnection();
        dao.in(inname,money,conn);
        dao.out(outname,money,conn);
    } catch (SQLException e) {
        cs=false;
        e.printStackTrace();
    }
    return cs;
}

在dao层代码
public class Transferdao{

public void out(String outname, double money,Connection conn) throws SQLException {
    QueryRunner runner=new QueryRunner();
    String sql="update user set price=price-money where pname=outname";
    runner.update(conn, sql);
}
public void in(String inname, double money,Connection conn) throws SQLException {
    QueryRunner runner=new QueryRunner();
    String sql="update user set price=price+money where pname=inname";
     runner.update(conn,sql);
}
四sir的主页 四sir | 菜鸟二级 | 园豆:206
提问于:2019-11-15 11:00
< >
分享
所有回答(2)
0

java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource
你的连接池的lib包,没有放到你的应用里

yytxdy | 园豆:1680 (小虾三级) | 2019-11-15 11:29
0

无法加载到这个类,看看你是否导入了,或者添加到build path了没有
java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource

麦奇 | 园豆:214 (菜鸟二级) | 2019-11-15 13:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册