I am creating a really rich java DB program, but I ran into a connection error. The code:
try{
Statement st;
ResultSet rs;
conn = DBConnection.dbconnection();
st = conn.createStatement();
String s = "select * from tab2DB order by Scadenza";
rs = st.executeQuery(s);
while(rs.next()){
ResultSet rs2;
PreparedStatement st2;
conn2 = DBConnection.connection();
String s2 = "select * from Prodotti where Nome = ?";
st2 = conn2.prepareStatement(s2);
st2.setString(1, rs.getString("Prodotto"));
rs2 = st2.executeQuery();
while(rs2.next()){
Date localDate = new Date();
String scadenza = rs.getString("Scadenza");
DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ITALIAN);
Date date = format.parse(scadenza);
if(localDate.after(date)){
conn3 = DBConnection.dbconnection();
String query ="insert into tabDB values ('"+nomeord+"','"+prodottoord+"','"+quantitΓ ord+"')";
Statement stmt;
stmt = conn3.createStatement();
stmt.executeUpdate(query);
conn3.close();
continue;
}
conn2.close();
rs2.close();
}
conn.close();
rs.close();
}
catch (SQLException e1) {
e1.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
the error is in if (localDate.after (date)) {...} where stmt.executeUpdate (request); causes an error and program crash. I think the problem here is that the DB already has a connection and it cannot handle conn3, but I need these other connections for the while loop, and at the same time I need to be able to give orders inside the if loop. How can I make the new order not interfere with while loops, but at the same time execute the request?
(what is trying to fulfill the request may not work in the code above, this is a fragment of the larger class path)
Thanks for the help!