[b]1、bean层[/b]
[b]2、util层[/b]
JavaBean
package Bean;
//物品类
public class Goods
{
private int goodsid; // 物品编号
public String goodsname; // 物品名称
private float price; // 物品单件
public void setGoodsid(int goodsid)
{
this.goodsid = goodsid;
}
public int getGoodsid()
{
return goodsid;
}
// 物品名称
public void setGoodsname(String goodsname)
{
this.goodsname = goodsname;
}
public String getGoodsname()
{
return goodsname;
}
// 物品价格
public void setPrice(float price)
{
this.price = price;
}
public float getPrice()
{
return price;
}
}
[b]2、util层[/b]
单例类
package util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DbConnection {
private static Connection conn=null;
private String driver="com.mysql.jdbc.Driver";
private String url="jdbc:mysql://localhost:3306/mydata";
private String user="root";
private String password="1234567";
private DbConnection(){
try {
Class.forName(driver);
conn=DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
if(conn==null){
new DbConnection();
}
return conn;