📄 goodservice.java
字号:
package dataservice;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import domain.Book;
import domain.Goods;
import domain.User;
import oracle.jdbc.OracleTypes;
public class GoodService extends Service {
public static void main(String[] args) {
GoodService gs = new GoodService();
ArrayList<Goods> goodses = gs.getAllGoodInfo();
System.out.println("goods list...");
for (int i = 0; i < goodses.size(); i++) {
System.out.println(goodses.get(i).getName());
}
String[]category = new String[3];
category[0] = "生活用品";
category[1] = "数学";
category[2] = "Java系列";
String errorMsg = gs.updateGoodInfo("05083224", "123", "2008060519134805083224",
"SUNCA SF845应急台灯", 50, 50, category);
System.out.println(errorMsg);
}
public String newGood(String userId, String password, String goodName,
double goodPrice, int goodNum, String[] category) {
open();
int isSuccessful = 0;
String errorMsg = null;
util.prepareCall("{ call newGood(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }");
util.setString(1, userId);
util.setString(2, password);
util.setString(3, goodName);
util.setDouble(4, goodPrice);
util.setInt(5, goodNum);
if (category != null) {
util.setString(6, category[0]);
util.setString(7, category[1]);
util.setString(8, category[2]);
}
util.registerOutParameter(9, OracleTypes.NUMERIC);
util.registerOutParameter(10, OracleTypes.VARCHAR);
util.execute();
isSuccessful = util.getInt(9);
errorMsg = util.getErrorMsg() + util.getString(10);
close();
if (isSuccessful == 1)
return null;
else
return errorMsg;
}
public String removeGood(String userId, String password, String goodId) {
open();
int isSuccessful = 0;
String errorMsg = null;
util.prepareCall("{ call removeGood(?, ?, ?, ?, ?) }");
util.setString(1, userId);
util.setString(2, password);
util.setString(3, goodId);
util.registerOutParameter(4, OracleTypes.NUMERIC);
util.registerOutParameter(5, OracleTypes.VARCHAR);
util.execute();
isSuccessful = util.getInt(4);
errorMsg = util.getErrorMsg() + util.getString(5);
close();
if (isSuccessful == 1)
return null;
else
return errorMsg;
}
public String releaseGood(String userId, String password, String goodId) {
open();
int isSuccessful = 0;
String errorMsg = null;
util.prepareCall("{ call releaseGood(?, ?, ?, ?, ?) }");
util.setString(1, userId);
util.setString(2, password);
util.setString(3, goodId);
util.registerOutParameter(4, OracleTypes.NUMERIC);
util.registerOutParameter(5, OracleTypes.VARCHAR);
util.execute();
isSuccessful = util.getInt(4);
errorMsg = util.getErrorMsg() + util.getString(5);
close();
if (isSuccessful == 1)
return null;
else
return errorMsg;
}
public String encloseGood(String userId, String password, String goodId) {
open();
int isSuccessful = 0;
String errorMsg = null;
util.prepareCall("{ call encloseGood(?, ?, ?, ?, ?) }");
util.setString(1, userId);
util.setString(2, password);
util.setString(3, goodId);
util.registerOutParameter(4, OracleTypes.NUMERIC);
util.registerOutParameter(5, OracleTypes.VARCHAR);
util.execute();
isSuccessful = util.getInt(4);
errorMsg = util.getErrorMsg() + util.getString(5);
close();
if (isSuccessful == 1)
return null;
else
return errorMsg;
}
public String updateGoodInfo(String userId, String password, String goodId,
String goodName, double goodPrice, int goodNum, String[] category) {
open();
int isSuccessful = 0;
String errorMsg = null;
util.prepareCall("{ call updateGoodInfo(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }");
util.setString(1, userId);
util.setString(2, password);
util.setString(3, goodId);
util.setString(4, goodName);
util.setDouble(5, goodPrice);
util.setInt(6, goodNum);
if (category != null) {
util.setString(7, category[0]);
util.setString(8, category[1]);
util.setString(9, category[2]);
}
util.registerOutParameter(10, OracleTypes.NUMERIC);
util.registerOutParameter(11, OracleTypes.VARCHAR);
util.execute();
isSuccessful = util.getInt(10);
errorMsg = util.getErrorMsg() + util.getString(11);
close();
if (isSuccessful == 1)
return null;
else
return errorMsg;
}
public String updateGoodStock(String userId, String password, String goodId, int goodNum) {
open();
int isSuccessful = 0;
String errorMsg = null;
util.prepareCall("{ call updateGoodStock(?, ?, ?, ?, ?, ?) }");
util.setString(1, userId);
util.setString(2, password);
util.setString(3, goodId);
util.setInt(4, goodNum);
util.registerOutParameter(5, OracleTypes.NUMERIC);
util.registerOutParameter(6, OracleTypes.VARCHAR);
util.execute();
isSuccessful = util.getInt(5);
errorMsg = util.getErrorMsg() + util.getString(6);
close();
if (isSuccessful == 1)
return null;
else
return errorMsg;
}
public String setGoodPrice(String userId, String password, String goodId, double goodPrice) {
open();
int isSuccessful = 0;
String errorMsg = null;
util.prepareCall("{ call setGoodPrice(?, ?, ?, ?, ?, ?) }");
util.setString(1, userId);
util.setString(2, password);
util.setString(3, goodId);
util.setDouble(4, goodPrice);
util.registerOutParameter(5, OracleTypes.NUMERIC);
util.registerOutParameter(6, OracleTypes.VARCHAR);
util.execute();
isSuccessful = util.getInt(5);
errorMsg = util.getErrorMsg() + util.getString(6);
close();
if (isSuccessful == 1)
return null;
else
return errorMsg;
}
public Goods getGood(String goodId) {
Goods goods = new Goods();
User user = new User();
open();
util.prepareCall("{ ? = call getGoodInfo(?) }");
util.registerOutParameter(1, OracleTypes.CURSOR);
util.setString(2, goodId);
util.execute();
ResultSet rs = util.getResultSet(1);
try {
if(rs.next()) {
goods.setId(rs.getString(1));
goods.setName(rs.getString(2));
goods.setPrice(rs.getDouble(3));
goods.setNumber(rs.getInt(4));
user.setId(rs.getString(5));
goods.setSaler(user);
goods.setCategory(rs.getString(6), 0);
goods.setCategory(rs.getString(7), 1);
goods.setCategory(rs.getString(8), 2);
if (rs.getInt(9) == 0)
goods.setReleased(false);
else
goods.setReleased();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close();
}
return goods;
}
public ArrayList<Goods> getAllGoodInfo() {
open();
util.prepareCall("{ ? = call getAllGoodInfo }");
util.registerOutParameter(1, OracleTypes.CURSOR);
util.execute();
ResultSet rs = util.getResultSet(1);
ArrayList<Goods> list = new ArrayList<Goods>();
try {
while(rs.next()) {
Goods goods = new Goods();
User user = new User();
goods.setId(rs.getString(1));
goods.setName(rs.getString(2));
goods.setPrice(rs.getDouble(3));
goods.setNumber(rs.getInt(4));
user.setId(rs.getString(5));
goods.setSaler(user);
goods.setCategory(rs.getString(6), 0);
goods.setCategory(rs.getString(7), 1);
goods.setCategory(rs.getString(8), 2);
if (rs.getInt(9) == 1 && goods.getNumber() > 0) {
goods.setReleased();
list.add(goods);
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close();
}
return list;
}
//TODO:getSomeGoodInfo
public ArrayList<Goods> getSomeGoodInfo() {
return null;
}
public String newBook(String userId, String password, String bookName,
double bookPrice, int bookNum, String[] category, String author,
String press, int edition, String isbn, String categoryNum) {
open();
int isSuccessful = 0;
String errorMsg = null;
util.prepareCall("{ call newBook(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }");
util.setString(1, userId);
util.setString(2, password);
util.setString(3, bookName);
util.setDouble(4, bookPrice);
util.setInt(5, bookNum);
if (category != null) {
util.setString(6, category[0]);
util.setString(7, category[1]);
}
util.setString(8, author);
util.setString(9, press);
util.setInt(10, edition);
util.setString(11, isbn);
util.setString(12, categoryNum);
util.registerOutParameter(13, OracleTypes.NUMERIC);
util.registerOutParameter(14, OracleTypes.VARCHAR);
util.execute();
isSuccessful = util.getInt(13);
errorMsg = util.getErrorMsg() + util.getString(14);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -