package dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import util.DBHelper;import enity.Items;public class ItemsDAO { /** * 獲得所有商品信息利用ArrayList * @param conn獲得連接對(duì)象 * @param stmt調(diào)用sql中數(shù)據(jù)庫信息 * @param res返回Result數(shù)據(jù)集 * @param sql獲得所有數(shù)據(jù)庫信息 * @param conn獲得連接對(duì)象 * @param list接受res的返回?cái)?shù)據(jù)集 *? */ public ArrayList<Items> getAllshangping(){ Connection conn=null;//數(shù)據(jù)庫連接 PreparedStatement stmt=null;//調(diào)用連接的數(shù)據(jù)庫信息 ResultSet res=null; ArrayList<Items> list=new ArrayList<Items>(); try{ conn=DBHelper.getConnection(); String sql="select * from items"; stmt=conn.prepareStatement(sql); res=stmt.executeQuery(); /** * 設(shè)置商品信息 */ while(res.next()){ Items item=new Items(); item.setId(res.getInt("id")); item.setName(res.getString("name")); item.setCity(res.getString("city")); item.setNumber(res.getInt("number")); item.setJiage(res.getInt("jiage")); item.setPicture(res.getString("pitcture")); list.add(item);//加入集合 } }catch(Exception ex){ ex.printStackTrace(); return null; } /** * 釋放所有資源,從小到大關(guān)閉 * 先關(guān)閉res,在是stmt */ finally{ if(res!=null){ try { res.close(); res=null; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(stmt!=null){ try { stmt.close(); stmt=null; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return list; }}package enity;public class Items { /** * 商品實(shí)體類 */ private int id; private String name; private String city; private int jiage; private int number; private String picture; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCity() { return city; } public void setCity(String city) { this.city = city; }public int getJiage() { return jiage; } public void setJiage(int jiage) { this.jiage = jiage; } public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } public String getPicture() { return picture; } public void setPicture(String picture) { this.picture = picture; }<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%@ page import="enity.Items"%><%@ page import="dao.ItemsDAO"%><% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>"><title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!-- <link rel="stylesheet" type="text/css" href="styles.css"> --><style type="text/css">div { float: left; margin: 10px;}div dd { margin: 0px; font-size: 10pt;}div dd.dd_name { color: blue;}div dd.dd_city { color: #000;}</style></head><body> <h1>商品展示</h1> <hr> <center> <table width="750" height="60" cellpadding="0" cellspacing="0" border="0"> <tr> <td> <!-- 商品循環(huán)開始 -->?<%? ItemsDAO items= new ItemsDAO();? ArrayList<Items> list = items.getAllshangping();? /*? *循環(huán)商品信息? */? if (list != null && list.size() > 0) {? for (int i = 0; i < list.size(); i++) {? Items item = list.get(i);?%> <div> <dl> <dt> <a href="details.jsp?id=<%=item.getId()%>"><img src="images/<%=item.getPicture()%>" width="120" height="90" border="1" /></a> </dt> <dd class="dd_name"><%=item.getName()%></dd> <dd class="dd_city"> 產(chǎn)地:<%=item.getCity()%> 價(jià)格:¥ <%=item.getJiage() %></dd> </dl> </div> <!-- 商品循環(huán)結(jié)束 --> <%? }? }?%> </td> </tr> </table> </center></body></html>執(zhí)行index。jsp文件時(shí)出現(xiàn)java.sql.SQLException: Column 'jiage' not found.求大神指點(diǎn)哪里錯(cuò)誤
javabean和Jsp?
黃森h(huán)uang
2016-11-13 18:37:02