📄 goodssettingdao.java
字号:
package dao.goodssetting;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.JOptionPane;
import vo.Goods;
import common.dbconnection.DbConnection;
public class GoodsSettingDao {
public boolean insertGoodsInfo(Goods value) {
boolean flag = false;
Connection con = null;
Statement stmt = null;
ResultSet set = null;
String sql = "insert into ktv_goods_info(GOODS_NAME, GOODS_UNIT, GOODS_COST_PRICE,"
+ "GOODS_SELL_PRICE,GOODS_STOCK,GOODS_ALERT,GOODS_ABBREVIATION)"
+ " values('"
+ value.getGoodsName()
+ "','"
+ value.getGoodsUnit()
+ "','"
+ value.getGoodsCostPrice()
+ "','"
+ value.getGoodsSellPrice()
+ "','"
+ value.getGoodsStock()
+ "','"
+ value.getGoodsAlert()
+ "','"
+ value.getGoodsAbbreviation() + "')";
System.out.println(sql);
try {
con = new DbConnection().getConnection();
stmt = con.createStatement();
set = stmt.executeQuery(sql);
if (set.next()) {
flag = true;
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "增加的商品"+e.getMessage().substring(10),
"插入提示", JOptionPane.YES_OPTION);
}
return flag;
}
public boolean deleteGoodsInfo(String goodsname) {
boolean flag = false;
Connection con = null;
PreparedStatement stmt = null;
ResultSet set = null;
String sql = "delete from ktv_goods_info where goods_name =?";
System.out.println(sql);
try {
con = new DbConnection().getConnection();
stmt = con.prepareStatement(sql);
stmt.setString(1, goodsname);
stmt.executeUpdate();
flag = true;
} catch (Exception e) {
System.out.println("异常信息: " + e.getMessage());
}
return flag;
}
public boolean updateGoodsInfo(Goods value) {
boolean flag = false;
Connection con = null;
PreparedStatement stmt = null;
ResultSet set = null;
try {
con = new DbConnection().getConnection();
String sql = "update ktv_goods_info set GOODS_UNIT='"
+ value.getGoodsUnit() + "', GOODS_COST_PRICE='"
+ value.getGoodsCostPrice() + "'," + "GOODS_SELL_PRICE='"
+ value.getGoodsSellPrice() + "',GOODS_STOCK='"
+ value.getGoodsStock() + "',GOODS_ALERT='"
+ value.getGoodsAlert()
+ "',GOODS_ABBREVIATION='"+value.getGoodsAbbreviation()+"' where GOODS_NAME = '"
+ value.getGoodsName() + "'";
System.out.println(sql);
stmt = con.prepareStatement(sql);
set = stmt.executeQuery(sql);
flag = true;
} catch (Exception e) {
System.out.println("异常信息: " + e.getMessage());
}
return flag;
}
public Vector getGoodsAbbreviationInfo(String value) {
Vector v = null;
Connection con = null;
Statement stmt = null;
ResultSet set = null;
String sql = "select * from KTV_Goods_INFO where goods_abbreviation like '%"
+ value.trim() + "%'";
System.out.println(sql);
try {
con = new DbConnection().getConnection();
stmt = con.createStatement();
set = stmt.executeQuery(sql);
v = new Vector();
while (set.next()) {
String GOODS_NAME = set.getString(1);
String GOODS_UNIT = set.getString(2);
double GOODS_COST_PRICE = set.getDouble(3);
double GOODS_SELL_PRICE = set.getDouble(4);
int GOODS_STOCK = set.getInt(5);
int GOODS_ALERT = set.getInt(6);
String GOODS_ABBREVIATION = set.getString(7);
v.addElement(new Goods(GOODS_NAME, GOODS_UNIT,
GOODS_COST_PRICE, GOODS_SELL_PRICE, GOODS_STOCK,
GOODS_ALERT, GOODS_ABBREVIATION));
}
} catch (Exception e) {
System.out.println("异常信息: " + e.getMessage());
}
return v;
}
public Vector getGoodsInfo() {
Vector v = null;
Connection con = null;
Statement stmt = null;
ResultSet set = null;
String sql = "select * from KTV_goods_INFO";
System.out.println(sql);
try {
con = new DbConnection().getConnection();
stmt = con.createStatement();
set = stmt.executeQuery(sql);
v = new Vector();
while (set.next()) {
String GOODS_NAME = set.getString(1);
String GOODS_UNIT = set.getString(2);
double GOODS_COST_PRICE = set.getDouble(3);
double GOODS_SELL_PRICE = set.getDouble(4);
int GOODS_STOCK = set.getInt(5);
int GOODS_ALERT = set.getInt(6);
String GOODS_ABBREVIATION = set.getString(7);
v.addElement(new Goods(GOODS_NAME, GOODS_UNIT,
GOODS_COST_PRICE, GOODS_SELL_PRICE, GOODS_STOCK,
GOODS_ALERT, GOODS_ABBREVIATION));
}
} catch (Exception e) {
System.out.println("异常信息: " + e.getMessage());
}
return v;
}
public Vector findRoomInfo(Goods goods) {
Vector v = null;
Connection con = null;
Statement stmt = null;
ResultSet set = null;
String sql = "select '" + goods.getGoodsName() + "' from ktv_goods_info";
System.out.println(sql);
try {
con = new DbConnection().getConnection();
stmt = con.createStatement();
set = stmt.executeQuery(sql);
v = new Vector();
while (set.next()) {
String GOODS_NAME = set.getString(1);
String GOODS_UNIT = set.getString(2);
double GOODS_COST_PRICE = set.getDouble(3);
double GOODS_SELL_PRICE = set.getDouble(4);
int GOODS_STOCK = set.getInt(5);
int GOODS_ALERT = set.getInt(6);
String GOODS_ABBREVIATION = set.getString(7);
v.addElement(new Goods(GOODS_NAME, GOODS_UNIT,
GOODS_COST_PRICE, GOODS_SELL_PRICE, GOODS_STOCK,
GOODS_ALERT, GOODS_ABBREVIATION));
}
} catch (Exception e) {
System.out.println("异常信息: " + e.getMessage());
}
return v;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -