私は単純なAccessデータベースを持っています。私は、このフィールドを持つテーブルがある:特定のキーを数字の自動インクリメント(オートナンバー)でAccessテーブルに挿入
CodOperazione (PK AutoNumber)
CodiceCliente (testo)
...
...
は今、私は別のデータベースからのデータで、この表をinizializeたいです。 私はこのテーブルにデータを書き込むコードを書いています。 これはコードである:データベースに挿入した後、ID 10が、(例えば50)ではない
"op.getCodiceOperazione() = 10"
場合は、このコードで
public Boolean insertOperazioneDareAvere(OperazioneCliente op, Boolean trasferimento) {
try{
Boolean result=false;
String query="";
if(trasferimento){
query="INSERT INTO OPERAZIONI (COdOperazione,CodiceCliente,"
+ "DataOperazione,Descrizione,Quantita,Importo,SommaDare,SommaAvere,Periodo,Anno,IDFattura) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?)";
}else{
query="INSERT INTO OPERAZIONI (CodiceCliente,"
+ "DataOperazione,Descrizione,Quantita,Importo,SommaDare,SommaAvere,Periodo,Anno,IDFattura) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?)";
}
int nColonna=1;
PreparedStatement stmt = db.prepareStatement(query);
if(trasferimento)
stmt.setInt(nColonna++, op.getCodOperazione());
stmt.setString(nColonna++, op.getCodiceCliente());
//if(trasferimento){
Timestamp yyyymmddXmas =
new Timestamp(yyyymmddFormat.parse(op.getDataOperazione()).getTime());
stmt.setTimestamp(nColonna++, yyyymmddXmas);
//}else
// stmt.setString(nColonna++, op.getDataOperazione());
if(op.getDescrizione()!=null && !op.getDescrizione().isEmpty() && op.getDescrizione().length()>0)
stmt.setString(nColonna++, op.getDescrizione());
else if(op.getDescrizioneRiscossione()!=null && !op.getDescrizioneRiscossione().isEmpty() && op.getDescrizioneRiscossione().length()>0)
stmt.setString(nColonna++, op.getDescrizioneRiscossione());
stmt.setInt(nColonna++, op.getQuantita()!=null ? op.getQuantita() : 0);
stmt.setDouble(nColonna++, op.getImporto()!=null ? op.getImporto() : 0.0);
stmt.setDouble(nColonna++, op.getSommaDare()!=null ? op.getSommaDare() : 0.0);
stmt.setDouble(nColonna++, op.getSommaAvere()!=null ? op.getSommaAvere() : 0.0);
stmt.setString(nColonna++, op.getPeriodo());
if(op.getAnno()==null){
stmt.setNull(nColonna++, Types.NULL);
}else{
stmt.setInt(nColonna++, op.getAnno());
}
if(op.getCodiceFattura()==null){
stmt.setNull(nColonna++, Types.NULL);
}else{
stmt.setInt(nColonna++, op.getCodiceFattura());
}
int n= stmt.executeUpdate(); // Ottengo il ResultSet dell'esecuzione della query
if(n>0 && !trasferimento){
result = true;
int id= getLastInsertID();
op.setCodOperazione(id);
}else{
System.out.println("codice operazione non inserita "+op.getCodOperazione());
}
//
stmt.close();
if(op.getCodiceFattura()!=null && op.getCodiceFattura()>0)
inserisciOperazioniInOpFattura(op);
return result;
}catch(Exception e){
log.logStackTrace(e);
return false;
}
}
。
ここで、特定の番号である自動インクリメントPKを使用してテーブルに挿入する方法を教えてください。 2歳以上である
UCanAccess JDBCドライバを使用していますか?もしそうなら、どのバージョン? –
私はUCanAccess 2.0.9.3バージョン – bircastri