Daoクラス
imprt java.sql.*;
import javax.naming.NamingException;
import -------;
public class Dao{
private static final String SELECT_USER_ID_SQL = "select * from user_id = ? and password = ?"
private static final String UPDATE_PRODUCT_SQL = "UPDATE PRODUCT SET" + "product_name = ?, price = ?, update_date = ? + where product_code = ?;"
public Product selectProduct(final String prodectCode) throws NameingExcepton, SQLException{
Connection conn = DaoUtil.getConnection();
Product product = null;
try{
PreapredStatement pstmt = conn.prepareStatement(SELECT_PRODUCT_SQL);
pstmt.setString(1,prodectCode);
ResultSet rs = pstmt.executeQuety();
if (rs.next()){
product = new Product();
product.setCode(rs.getString("PRODUCT_CODE"));
product.setName(rs.getString("PRODUCT_NAME"));
product.setPrice(rs,getUnt("PRICE"));
product.setUpdateDate(rs.getTimestamp("UPDATE_DATE"));
}
pstmt.close();
}finally{
DaoUtil.closeConnection(conn);
}
return product;
}
public int updateProduct(final Product product) throws NameingException,SQLException{
Connection conn = DaoUtil.getConnection();
int updateCount = 0;
try{
PreapredStatement pstmt = conn.prepareStatement(UPDATE_PRODUCT_SQL);
pstmt.setString(1,product.getName());
pstmt.setInt(2,product.getPrice());
pstmt.setTimestamp(3,new Timestamp(System.currentTimeMillis()));
pstmt.setString(4,profuct.getcode());
updateCount = pstmt.executeUpdate()):
pstmt.close();
}finally{
DaoUtil.closeConnection(conn);
}
return updateCount;
}
}
最終更新:2014年08月17日 20:06