joyoon00
(Jeongon Yoon)
1
I would like to perform provisioning in ISC using a JDBC connector and specify insert queries for two different tables.
Here is the code snippet I am considering:
// First statement
statement1 = connection.prepareStatement(sql1);
statement1.setString(1, req.getValue());
statement1.setString(2, user_id);
statement1.executeUpdate();
statement1.close();
// Second statement
statement2 = connection.prepareStatement(sql2);
statement2.setString(1, req.getValue());
statement2.setString(2, req.getValue());
statement2.setString(3, user_id);
statement2.executeUpdate();
statement2.close();
Is this a valid approach?
If not, could you suggest a better way to insert data into two different tables within the same transaction?
Thank you in advance!
gourab
(Gourab Sadhukhan)
2
Hi @joyoon00
I can give you some theoretical jdbc suggestions:
- Check if data already exists in tables
- The
setAutoCommit(false)
call ensures that the changes made by both statements are not automatically committed to the database.
- If both statements succeed, the
commit()
method is called to apply the changes.
- If either statement fails, the
rollback()
method is called to undo changes from both statements, maintaining database integrity.
- Finally, always ensure resources are closed properly in the
finally
block
IAMpdu
(Prasad Uplenchwar)
3
Hello @joyoon00 , you can do that and yes it is valid, if you want to build a complex logic you can build JAR file and refer that in JDBC PROV rule.