【问题标题】:i want to load data from mysql to jsp but I have an unprocessable error我想将数据从 mysql 加载到 jsp,但我有一个无法处理的错误
【发布时间】:2018-06-30 07:27:00
【问题描述】:
enter code here
  1. 这是从数据库加载数据到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;
        };
    
    }
    
  2. 这是显示数据的html文件,我是加载类

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

错误部分将在评论中发布

【问题讨论】:

    标签: java mysql apache jsp


    【解决方案1】:

    我不确定我的答案,但是... 方法 connect.prepareCall 从数据库调用存储过程,所以,你可能应该使用 connect.prepareStatement。

    【讨论】:

    • 我尝试了但没有成功!
    • lỗi thông báo ở đoạn code này PreparedStatement ps = (PreparedStatement) connect.prepareStatement(sql);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多