张三张三张三注册 2019-09-12 17:31 采纳率: 100%
浏览 1208
已采纳

jdbc无法连接MySQL数据库

报错信息:No suitable driver found for jdbc:mysql://localhost:3306/utf-8?useUnicode=true&characterEncoding=utf-8
我写的url:url="jdbc:mysql://localhost:3306/utf-8?useUnicode=true&characterEncoding=utf-8";
直接用main方法调用连接可以正常查询,但是从action中调用就会报错
这是采用main方法调用

public static void main(String[] args) {
        UserBiz ubiz=new UserBizImpl();
        String username="张三";
        String password="123";
        Users user=ubiz.getUser(username, password);
        System.out.println(user);
    }

这是在action中调用

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username=request.getParameter("username");
        System.out.println(username);
        String password=request.getParameter("password");
        System.out.println(password);
        UserBiz ubiz=new UserBizImpl();
        Users user=ubiz.getUser(username, password);
  • 写回答

2条回答 默认 最新

  • 毕小宝 博客专家认证 2019-09-13 14:45
    关注

    这里的报错是 IO 异常而不是 JDBC 的呢,贴出完整的异常看看。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?