Ciao, ho un problema:
faccio un insert(con successo) all'interno di un for.
Ma dopo l'inserimento mi da questo errore: No ResultSet Was Produced
Vi evidenzio la riga in questione (credo)
public void confermaAcquisto() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbcdbc:gema.mdb");
int carica = 0;
int caric=0;
double prezzo = 0;
double prezzopar = 0;
long max=0;
long id=0;
long idart=0;
int scarico=0;
String codice="";
String des="";
con.setAutoCommit(true);
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSIT IVE,ResultSet.CONCUR_UPDATABLE);
for (int i = 0; i < v.size(); i++) {
codice = ((Prodotto)v.elementAt(i)).getCodice();
JOptionPane.showMessageDialog(null,
"" + codice, "MESSAGGIO",
JOptionPane.INFORMATION_MESSAGE);
ResultSet res = stmt.executeQuery(
"SELECT * FROM Articoli WHERE Codice =" + "'" + codice + "'");
while (res.next())
caric = res.getInt("Esistenza");
res.close();
carica = caric + ( ( (Prodotto) v.elementAt(i)).getQta());
JOptionPane.showMessageDialog(null,
"" + carica, "MESSAGGIO",
JOptionPane.PLAIN_MESSAGE);
stmt.executeUpdate("UPDATE Articoli SET Esistenza='" +
carica +
"' WHERE Codice ='" +
( (Prodotto) v.elementAt(i)).getCodice() + "'");
System.out.println(carica);
prezzopar = ( ( (Prodotto) v.elementAt(i)).getPrezzo()); //*((Prodotto)v.elementAt(i)).getQta();
prezzo = prezzopar + prezzo;
}
Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSIT IVE,ResultSet.CONCUR_UPDATABLE);
ResultSet res3 = stmt1.executeQuery("SELECT Numero FROM MovimentiMagazzino ");
res3.last();
id=res3.getLong(1);
res3.close();
JOptionPane.showMessageDialog(null,
"numero " + id, "MESSAGGIO",
JOptionPane.PLAIN_MESSAGE);
for(int i=0;i<v.size();i++){
int ca=((Prodotto)v.elementAt(i)).getQta();
int tipo12=1;//1 carico 2 scarico
boolean a=false;
idart=((Prodotto)v.elementAt(i)).getIdArticolo();
codice=((Prodotto)v.elementAt(i)).getCodice();
des=((Prodotto)v.elementAt(i)).getDescrizione();
String dep="";
if(codicedeposito==1){
dep="DEP";
JOptionPane.showMessageDialog(null,"Stai Lavorando dentro"+dep,"Messaggio",JOptionPane.INFORMATION_ME SSAGE);
}else{
dep="01";
JOptionPane.showMessageDialog(null,"Stai Lavorando dentro"+dep,"Messaggio",JOptionPane.INFORMATION_ME SSAGE);
}
// String query="INSERT into MovimentiMagazzino(Data,Anno,Carico,Scarico,ID Articolo,Codice,Descrizione,CodiceDeposito,CostoEU ,AvvaloroCosto,Tipo12)VALUES("+data+","+anno+","+c a+","+scarico+","+idart+",'"+codice+"','"+des+"',' "+dep+"',"+prezzo+","+a+","+tipo12+")";
id= id + 1;
String query="INSERT into MovimentiMagazzino (Numero,Data,Anno,Carico,Scarico,[ID Articolo],Codice,Descrizione,CodiceDeposito,CostoEU,Avvalor oCosto,Tipo12) VALUES ("+id+",#"+data+"#,"+anno+","+ca+","+scarico+","+i dart+",'"+codice+"','"+des+"','"+dep+"',"+prezzo+" ,"+a+","+tipo12+")";
System.out.print(query);
System.out.print("");
System.out.println();
Statement stmt2 = con.createStatement();
JOptionPane.showMessageDialog(null, "numero inc"+id,
"CARICO", JOptionPane.INFORMATION_MESSAGE);
stmt2.executeQuery(query);
stmt2.close();
}
JOptionPane.showMessageDialog(null, "CARICO EFFETTUATO CON SUCCESSO",
"CARICO", JOptionPane.INFORMATION_MESSAGE);
double iva = prezzo * (1.2);
JOptionPane.showMessageDialog(null,
"ACQUISTO ESEGUITO TOTALE PREZZO " + iva +
" IVA INC", "MESSAGGIO",
JOptionPane.PLAIN_MESSAGE);
ta.setText("");
// v.removeAllElements();
}
catch (Exception e) {
ta.setText("Problema: " + e.toString());
JOptionPane.showMessageDialog(null, "error", "error",
JOptionPane.PLAIN_MESSAGE);
}
}