JDBC 6.29

//实体类 ProductInfo

package com.entiy.bean;



import java.io.Serializable;


public class ProductInfo implements Serializable{
/**
* 定义类编号
*/
private static final long serialVersionUID = 1L;
private int pid;
private String pname;
private double pprice;
private int ptype;
private String pdesc ;
private int pstatus ;
@Override
public String toString() {
// return "ProductInfo [pid=" + pid + ", pname=" + pname + ", pprice=" + pprice + ", ptype=" + ptype + ", pdesc="
// + pdesc + ", pstatus=" + pstatus + "]";
return "" + pid + "\t" + pname + "\t" + pprice + "\t" + ptype + "\t"
+ pdesc + "\t" + pstatus;
}
public ProductInfo() {
super();
// TODO Auto-generated constructor stub

}


public ProductInfo(int pid, String pname, double pprice, int ptype, String pdesc, int pstatus) {
super();
this.pid = pid;
this.pname = pname;
this.pprice = pprice;
this.ptype = ptype;
this.pdesc = pdesc;

}
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public String getPname() {
return pname;
}
public void setPname(String pname) {
this.pname = pname;
}
public double getPprice() {
return pprice;
}
public void setPprice(double pprice) {
this.pprice = pprice;
}
public int getPtype() {
return ptype;
}
public void setPtype(int ptype) {
this.ptype = ptype;
}
public String getPdesc() {
return pdesc;
}
public void setPdesc(String pdesc) {
this.pdesc = pdesc;
}
public int getPstatus() {
return pstatus;
}
public void setPstatus(int pstatus) {
this.pstatus = pstatus;
}

}


package com.entiy.bean;


import java.io.Serializable;

/**

实体类 UserInfo

*/

public class UserInfo implements Serializable{
/**
* 类编号
*/
private static final long serialVersionUID = 1L;
private int uid;
private String uname;
private String upass;
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getUpass() {
return upass;
}
public void setUpass(String upass) {
this.upass = upass;
}
public UserInfo(int uid, String uname, String upass) {
super();
this.uid = uid;
this.uname = uname;
this.upass = upass;
}
public UserInfo() {
super();
// TODO Auto-generated constructor stub
}
@Override
public String toString() {
return "UserInfo [uid=" + uid + ", uname=" + uname + ", upass=" + upass + "]";
}

}


//JDBC连接工具类


package com.entiy.utils;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Info_utils {

    //静态代码块  初始化类

static {

try {

                    

Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

        //定义一个连接对象Connection的方法

public static Connection getConnection() throws SQLException {
return DriverManager.getConnection("jdbc:mysql://localhost:3306/info", "root", "1234");
}
//关闭所有连接的一些方法
public static void closeS(Connection con,Statement sm,PreparedStatement psm,ResultSet rs) throws SQLException {
if (con != null) {
con.close();
con = null;
}

if (sm != null) {
sm.close();
sm = null;
}

if (psm != null) {
psm.close();
psm = null;
}

if (rs != null) {
rs.close();
rs = null;
}
}

}



package com.entiy.dao;


import java.util.List;


import com.entiy.bean.ProductInfo;
import com.entiy.bean.UserInfo;

//定义一个DaoProduct_info 接口
public interface DaoProduct_info {

/**
* 查询并返回所有商品信息
* @return
*/
List<ProductInfo> getAllProdcutInfos();
/**
* 查询对应商品信息
* @param id
* @return
*/
ProductInfo getProductInfobyid(String name);
/**
* 修改商品信息并返回修改结果
* @param id
* @return
*/
boolean updateProdcutInfoById(ProductInfo info,int id);

boolean deleteProdcutInfoById(int id);




package com.entiy.dao;


import java.util.List;


import com.entiy.bean.ProductInfo;
import com.entiy.bean.UserInfo;

//定义一个DaoUser_Info接口
public interface DaoUser_Info {
/**
* 添加用户信息并返回添加结果
* @param user
* @return
*/
boolean addUserInfo(UserInfo user);
/**
* DaoProduct_info
* 查询对应用户信息的数量并将结果返回
* @param user
* @return
*/
boolean queryUserInfo(UserInfo user);
}


}

猜你喜欢

转载自blog.csdn.net/wljgg666/article/details/80855990