javabean和Jsp?

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获得连接对象

* @param stmt调用sql中数据库信息

* @param res返回Result数据集

* @param sql获得所有数据库信息

* @param conn获得连接对象

* @param list接受res的返回数据集

*/

public ArrayList<Items> getAllshangping(){

Connection conn=null;//数据库连接

PreparedStatement stmt=null;//调用连接的数据库信息

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();

/**

* 设置商品信息

*/

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;

}

/**

* 释放所有资源,从小到大关闭

* 先关闭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 {

/**

* 商品实体类

*/

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>

<!-- 商品循环开始 --> 

<%

  ItemsDAO items= new ItemsDAO();

  ArrayList<Items> list = items.getAllshangping();

  /*

  *循环商品信息

  */

  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">

产地:<%=item.getCity()%>&nbsp;&nbsp;价格:¥

<%=item.getJiage() %></dd>

</dl>

</div> <!-- 商品循环结束 -->

<%

  }

  }

 %>

</td>

</tr>

</table>

</center>

</body>

</html>

执行index。jsp文件时出现

java.sql.SQLException: Column 'jiage' not found.求大神指点哪里错误



黄森huang
浏览 1257回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java