아래의 StaticSentence를 사용하여 포스트그레스에서 테이블을 만들었습니다. 테이블 읽기는 다른 테이블 제품에서 만들어지며 스키마가 필요하기 때문에 데이터가 삭제됩니다 (이 기능은 정말 새로운 기능이지만이를 처리하는 데 더 좋은 방법이 될 것입니다).postgres 오류 : "id"열이 없습니다.
public void syncProductsBefore() throws BasicException {
new StaticSentence(s,"CREATE TABLE PRODUCTS_imports(ID) WITH OIDS AS SELECT * FROM PRODUCTS ").exec();
new StaticSentence(s, "DELETE FROM PRODUCTS_imports").exec();
}
그러면 아래의 방법으로 PreparedSentence를 사용하여이 테이블에 기록하려고합니다. 새 데이터를 삽입하거나 기존 데이터를 업데이트할지 여부를 알기 위해 먼저 업데이트 명령이 실행됩니다.
공개 무효 syncProduct (최종 ProductInfoExt 자극)을 BasicException
{
Transaction t = new Transaction(s) {
public Object transact() throws BasicException {
/*Sync the Product in a transaction*/
/* Try to update*/
if (new PreparedSentence(
s,
"UPDATE PRODUCTS SET REFERENCE = ?, CODE = ?, NAME = ?, PRICEBUY = ?, PRICESELL = ?, CATEGORY = ?, TAXCAT = ?, IMAGE = ? WHERE ID = ?",
SerializerWriteParams.INSTANCE).exec(new DataParams() {
public void writeValues() throws BasicException {
setString(1, prod.getReference());
setString(2, prod.getCode());
setString(3, prod.getName());
// setBoolean(x, p.isCom());
// setBoolean(x, p.isScale());
setDouble(4, prod.getPriceBuy());
setDouble(5, prod.getPriceSell());
setString(6, prod.getCategoryID());
setString(7, prod.getTaxCategoryID());
setBytes(8, ImageUtils.writeImage(prod.getImage()));
// setDouble(x, 0.0);
// setDouble(x, 0.0);
setString(9, prod.getID());
}
}) == 0) {
/* leyonce */
/**
* If not updated, try to insert insert into the import
* temporary table create temporary sorted copies of product
* catalog and products
*/
new PreparedSentence(
s,
"INSERT INTO PRODUCTS_imports(ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, CATEGORY, TAXCAT, IMAGE, STOCKCOST, STOCKVOLUME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
SerializerWriteParams.INSTANCE)
.exec(new DataParams() {
public void writeValues() throws BasicException{
/*leyonce --insert values into temporary import table*/
setString(1, prod.getID());
setString(2, prod.getReference());
setString(3, prod.getCode());
setString(4, prod.getName());
setBoolean(5, prod.isCom());
setBoolean(6, prod.isScale());
setDouble(7, prod.getPriceBuy());
setDouble(8, prod.getPriceSell());
setString(9, prod.getCategoryID());
setString(10, prod.getTaxCategoryID());
setBytes(11, ImageUtils.writeImage(prod
.getImage()));
setDouble(12, 0.0);
setDouble(13, 0.0);
)을 발생; }
지금 업데이트가 완벽하게 실행되지만 컴파일러가 삽입 문에 도달 할 때, 그것은 롤백하고 난 정말 왜하지 않는 오류
org.postgresql.util.PSQLException:
ERROR: column "id" does not exist
Position: 84
를 반환합니다.
StaticSentence 및 PreparedSentence 란 무엇입니까? 그 맞춤 래퍼가 * JDBC * 클래스, 즉'PreparedStatement' 주위에 있습니까? Google PreparedSentence를 검색하면 * JDBC * 클래스에서 파생 된 몇 가지 다른 사용자 정의 클래스가 나타납니다. – khampson
예, 그렇습니다. – TheEYL
'products '테이블에 대한'create table' 문을 보여주십시오. –