erwaisme 2021-07-15 13:08 采纳率: 100%
浏览 33
已采纳

JSP里面运行不了SQL(在JAVA类里面能运行)

代码如下:

JSP:

<div class="container">
    <table class="table table-striped table-hover">
        <tr>
            <th>编号</th>
            <th>名字</th>
            <th>价格</th>
            <th>库存</th>
            <th>生产日期</th>
            <th>操作</th>
        </tr>
        <%
            //定义集合 存储商品信息
            ArrayList<Shops> list = new ArrayList<Shops>();

            //通过JDBC把数据库值取给List
            Class.forName("com.gzlg.bigdata.Database");
            String name = "root";
            String pwd = "123456";
            String url = "jdbc:mysql://localhost:3306/wrok?useSSL=false&serverTimezone=UTC";
            Connection connection = DriverManager.getConnection(url, name, pwd);
            String sql = "SELECT * FROM shops;";
            PreparedStatement pst = connection.prepareStatement(sql);
            ResultSet res = pst.executeQuery();
            while (res.next()) {
                Shops shops1 = new Shops();
                shops1.setShopid(res.getInt(1));
                shops1.setShopName(res.getString(2));
                shops1.setPrice(res.getFloat(3));
                shops1.setCount(res.getInt(4));
                shops1.setMakedate(res.getString(5));
                list.add(shops1);
            }
            for (int i = 0; i < list.size(); i++) {
                out.print("     <tr >\n" +
                        "            <td >" + list.get(i).getShopid() + " </td >\n" +
                        "            <td > " + list.get(i).getShopName() + " </td >\n" +
                        "            <td > " + list.get(i).getPrice() + " </td >\n" +
                        "            <td > " + list.get(i).getCount() + " </td >\n" +
                        "            <td > " + list.get(i).getMakedate() + "</td >\n" +
                        "        </tr >");

            }

        %>


    </table>

  
</div>

然后通过Tomcat运行出来就报:

javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/wrok?useSSL=false&serverTimezone=UTC 这个错误。
已经将jar放Tomcat目录的lib下还是运行不了。

  • 写回答

3条回答 默认 最新

  • CSDN专家-sinJack 2021-07-15 13:10
    关注

    你加载的驱动都写错了,报错的意思也是没有找到合适的驱动。
    Class.forName("com.gzlg.bigdata.Database");
    改为
    Class.forName("com.mysql.jdbc.Driver");
    如有帮助望采纳。点击我回答右上角【采纳】按钮。

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

报告相同问题?

问题事件

  • 已采纳回答 7月15日
  • 创建了问题 7月15日

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理