java—我想将数据从mysql加载到jsp,但有一个无法处理的错误

r9f1avp5  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(251)
enter code here

这是将数据从数据库加载到jsp的java代码
包道;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import model.Category;
import utils.DBConnect;

public class CategoryDAO {

    public ArrayList<Category> getListCategory() throws SQLException {
        Connection connect = DBConnect.getConnection();
        ArrayList<Category> listCategory = new ArrayList<>();
        String sql = "SELECT * FROM category";
        PreparedStatement ps = connect.prepareCall(sql);
        ResultSet rs = ps.executeQuery();

        while (rs.next()) {
            Category category = new Category();
            category.setCategoryID(rs.getInt("CategoryID"));
            category.setCategoryName(rs.getString("CategoryName"));
            listCategory.add(category);
        }

        return listCategory;
    };

}

这是html文件显示数据,我是加载类

<ul class="drop">
                             <%
                                for (Category c : cateDao.getListCategory()) {
                             %>
                                <li><a href="product.jsp?category=<%=c.getCategoryID()%>"><%= c.getCategoryName() %></a></li>
                             <% 
                                } 
                             %>
                            </ul>

错误部分将发布在评论中

ohtdti5x

ohtdti5x1#

我不确定我的答案,但是。。。方法connect.preparecall从数据库中调用存储过程,因此,可能您应该改用connect.preparestatement。

相关问题