1) Can I use one prepared statement to pass data to multiple tables from java? where I am using JDBC driver.
try
{
conn = ac.getConnection();
String insert = "INSERT INTO PPN_WORKFLOW(C2_F_Date,C2_Completed) VALUES(?,?)";
stmt = conn.prepareStatement(insert);
stmt.setDate(1, date);//question 2
stmt.setInt(2, 1);
stmt.executeUpdate();
stmt.close();
String insert2 = "INSERT INTO CREATE_ERF(Purc_Part_New_F_Date,Purc_Part_New_Completed) "
+ "VALUES(?,?)";
stmt = conn.prepareStatement(insert2);
stmt.setDate(1, date);
stmt.setInt(2,1);
stmt.executeUpdate();
}
catch(SQLException | ClassNotFoundException e) {e.printStackTrace();}
finally
{
if(stmt != null) {
stmt.close();
}
if(conn != null) {
conn.close();
}
}
Here I am using stmt(PreparedStatement) for table PPN_WORKFLOW and CREATE_ERF?
2) the PPN_WORKFLOW table consists of more paremeters like
PPN_WORKFLOW(C1_S_Date,C2_F_Date,C2_Completed)
but I would like to update 2 and 3 parameter, So Is my code is correct.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…