【Java开源代码栏目提醒】:网学会员为需要Java开源代码的朋友们搜集整理了WareDao.java相关资料,希望对各位网友有所帮助!
package com.dao;
import com.tool.JDBConnection;
import java.util.*;
import com.domain.WareVO;
import java.sql.*;
public class WareDao {
private JDBConnection connection = null;
public WareDao() {
connection = new JDBConnection();
this.connection.creatConnection(); //利用构造方法调用类中的对象对数据库创建连接
}
public List wareSelect() {
List list = new ArrayList();
WareVO ware = null;
String sql = "select * from tb_inware order by id";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
ware = new WareVO();
ware.setId(Integer.valueOf(rs.getString(1)));
ware.setNumber(rs.getString(2));
ware.setName(rs.getString(3));
ware.setKind(rs.getString(4));
ware.setBusiness(rs.getString(5));
ware.setAccount(Integer.valueOf(rs.getString(6)));
ware.setMeasure(rs.getString(7));
ware.setRemark(rs.getString(8));
ware.setMoney(rs.getFloat(9));
list.add(ware);
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return list;
}
public WareVO wareSelectOne(String number) {
WareVO ware = null;
String sql = "select * from tb_inware where number='" + number + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
ware = new WareVO();
ware.setId(Integer.valueOf(rs.getString(1)));
ware.setNumber(rs.getString(2));
ware.setName(rs.getString(3));
ware.setKind(rs.getString(4));
ware.setBusiness(rs.getString(5));
ware.setAccount(Integer.valueOf(rs.getString(6)));
ware.setMeasure(rs.getString(7));
ware.setRemark(rs.getString(8));
ware.setMoney(rs.getFloat(9));
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return ware;
}
//查找货品的名称
public String wareName(String number) {
String name = null;
String sql = "select * from tb_inware where number='" + number + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
name = rs.getString("name");
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return name;
}
//查找货品规格
public String wareMeasure(String number) {
String measure = null;
String sql = "select * from tb_inware where number='" + number + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
measure = rs.getString("measure");
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return measure;
}
//查找货品的名称
public int wareAccount(String number) {
int account =0;
String sql = "select * from tb_inware where number='" + number + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
account = rs.getInt("account");
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return account;
}
public WareVO wareSelectName(String name) {
WareVO ware = null;
String sql = "select * from tb_inware where name='" + name + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
ware = new WareVO();
ware.setId(Integer.valueOf(rs.getString(1)));
ware.setNumber(rs.getString(2));
ware.setName(rs.getString(3));
ware.setKind(rs.getString(4));
ware.setBusiness(rs.getString(5));
ware.setAccount(Integer.valueOf(rs.getString(6)));
ware.setMeasure(rs.getString(7));
ware.setRemark(rs.getString(8));
ware.setMoney(rs.getFloat(9));
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return ware;
}
//添加操作
public void wareInsert(WareVO vo) {
String
sql = "insert into tb_inware values('" + vo.getNumber() + "','" +
vo.getName() + "','" + vo.getKind() + "','" + vo.getBusiness() + "','" +
vo.getAccount() + "','" + vo.getMeasure() + "','" + vo.getRemark() +
"','" + vo.getMoney() + "') ";
connection.executeUpdate(sql);
connection.closeConnection();
}
public void wareDelete(Integer id) {
String sql = "delete from tb_inware where id='" + id + "'";
connection.executeUpdate(sql);
connection.closeConnection();
}
public void wareUpdateNumber(Integer id, String number) {
String unNumber = "ware-" + String.valueOf(id);
String sql = "update tb_inware set number='" + unNumber +
"' where number='" + number + "'";
connection.executeUpdate(sql);
connection.closeConnection();
}
public void wareUpdate(WareVO vo) {
String sql = "update tb_inware set name='" + vo.getName() + "',kind='" +
vo.getKind() +
"',business='" + vo.getBusiness() + "',measure='" + vo.getMeasure() +
"',remark='" + vo.getRemark() + "',money='" + vo.getMoney() +
"',account='" + vo.getAccount() + "' where id='" + vo.getId() + "'";
connection.executeUpdate(sql);
connection.closeConnection();
}
public void wareIn(Integer i