- 22
- 0
- 约8.44千字
- 约 10页
- 2017-05-27 发布于河南
- 举报
《Java Web开发基础》实验报告
参考代码:
package kccx.entity;
public class Storage {
private int id; // 商品编号
private String name; // 商品名
private double price; // 价格
private String type; // 商品类型
private int number; // 商品数量
private String makeTime; // 生产日期
private int useDay; // 有效期
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getMakeTime() {
return makeTime;
}
public void setMakeTime(String makeTime) {
this.makeTime = makeTime;
}
public String getName() {
return name;
}
public void setName(String name) {
= name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getUseDay() {
return useDay;
}
public void setUseDay(int useDay) {
this.useDay = useDay;
}
} 编写数据访问类:StorageDao,在Dao类中编写常量和方法。
常量:驱动、URL、用户名、密码、商品类型。
方法1:连接数据库。
方法2:关闭数据库。
方法3:按字段排序查询。
方法4:按商品类型查询。
参考代码:
package kccx.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.ArrayList;
import kccx.entity.Storage;
public class StorageDao {
public static final String WIRING = 电器;
public static final String FOOD = 食品;
public static final String CLOTHING = 服装;
public static final String COMMODITY = 日用品;
public final static String DRIVER = com.microsoft.sqlserver.jdbc.SQLServerDriver; // 数据库驱动
public final static String URL =
jdbc:sqlserver://localhost:1433;DataBaseName=store; // 数据库URL
public final static String DBNAME = sa; // 数据库用户名
public final static String DBPASS = sa; // 数据库密码
private Connection conn = null; // 数据库连接
private PreparedStatement pstmt = null; // PreparedStatement对象
private ResultSet rs = null; // 结果集对象
/**
*
原创力文档

文档评论(0)