package serv; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.RowMapper; import entity.Material; public class MaterialService extends BaseService { /** * 把一条材料信息加入到数据库中 */ public void addMr(String mtime,String mzno,String mpeople,String mname,String mquantity,double mmoney,String mno){ try { String sql = "insert into Material(mtime,mzno,mpeople,mname,mquantity,mmoney,mno) VALUES(?,?,?,?,?,?,?)"; jt.update(sql,mtime,mzno,mpeople,mname,mquantity,mmoney,mno); } catch (DataAccessException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } /** * 根据mno查询材料 */ public Material getmaterialBymno (String mno)throws DataAccessException{ Material material = null; try { String sql = "select * from material where mno= ?"; material = jt.queryForObject(sql,new MaterialRowMapper(), mno); } catch (DataAccessException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return material; } /** *删除材料 ->1 * @param sno * @throws DataAccessException */ public void deleteMaterial(String mno) throws DataAccessException{ String sql = "delete from Material where mno=? "; jt.update(sql,mno); } /** * 获取所有材料信息 */ public ArrayList<Material> getAllMaterial(String mtime){ ArrayList<Material> al = null; try { String sql = "select * from material "; al = (ArrayList<Material>)jt.query(sql,new MaterialRowMapper()); } catch (DataAccessException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return al; } private class MaterialRowMapper implements RowMapper<Material> { public Material mapRow(ResultSet rs, int rownum) throws SQLException { Material material= new Material(); material.setMno(rs.getString("mno")); material.setMname(rs.getString("mname")); material.setMtime(rs.getString("mtime")); material.setMpeople(rs.getString("mpeople")); material.setMzno(rs.getString("mzno")); material.setMquantity(rs.getString("mquantity")); material.setMmoney(rs.getDouble("mmoney")); return material; } } }
- 粉丝: 0
- 资源: 2
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助