I'm doing a test with DB4O. I am trying to insert data. The problem I have is:
When I insert the name of winery and D.O. I have to insert only if not exist in the database.
How could i do it?
This is my insert code:
Scanner teclado=new Scanner(System.in);
try{
ObjectContainer db= Db4oEmbedded.openFile("DB4O.yap");
System.out.print("Name of Wine: ");
String nomVino = teclado.next();
System.out.print("Name of Cellar: ");
String nomBodega = teclado.next();
System.out.print("D.O: ");
String DO = teclado.next();
System.out.print("Type of Wine: ");
String tipoVino = teclado.next();
System.out.print("Grad: ");
float gradosAlch = teclado.nextFloat();
System.out.print("Year of wine: ");
int fecha = teclado.nextInt();
teclado.close();
Vinos v = new Vinos(nomVino,new Bodega(nomBodega,DO),tipoVino,gradosAlch,fecha);
db.store(v); //guardar objetos
db.commit(); // valida los datos
//odb.rollback(); // deshace los datos
System.out.print("Vino Introducido\n");
db.close(); //cerrar la bd
}
catch(Exception e){System.out.println (e);}
}
Thank you in advance!