August 19th, 2004, 12:53 PM
Help in application structure
I have a application that updates several table at 1 time. But now i want to make sure that any failure in updating any 1 of the tables, the database would rollback to the original state. How should i design the structure of my application?
JSP page --- >> Servlet --- >> Controller --- >> Database
In my jsp page, this is where the user enters the data and submit. The servlet would capture all the data that the user enter into the textfield. The Controller class is a file, which i code to manage the updating of the records and also responsible for calling other classes to update to the database. For the database class it is just a class i coded to connect to database, and accept SQL statements through a method to perform insert,update,delete,query.
In my controller, i would call Class A and B to perform update operations.
so in Class A and B i would have something that look like this
in my database class
public class A
public void updateRecord()
String sql = // here goes my sql update statement...
Database db = new Database();
in my controller class
public class Database
public void executeUpdate(String sql)
// all the update to database goes here
where should i insert the codes to ensure the updating of the records smoothly?
public class UpdateController()
A a = new A();
B b = new B();
August 19th, 2004, 10:23 PM
Rusty here long time since I've played with tables at the programatical level but don't you have to do a comitt for the changes to stay? So if I you do x updates wait on doing the comitt until all x updates are successful, if any of the x fail do a roll back.
If you spend more on coffee than on IT security, you will be hacked. What\'s more, you deserve to be hacked.
-- former White House cybersecurity adviser Richard Clarke
August 19th, 2004, 10:34 PM
I am not sure of your question here..........are you wanting to update an entire record, or allow partial updates?
I am guessing that you are holding your database in more than one table?
I need a little bit more information, but I would guess that you should create forms for each section of the database, then link those?
August 19th, 2004, 11:16 PM
This should have info on what you are looking for: http://www.fawcette.com/javapro/archives/bs0999/
What you are discussing is called transaction processing, it uses Commit and Rollback functionality to ensure the inserts/updates/deletes/whatever are proper before applying any one set of changes.
The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
\"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
Is your whole family retarded, or did they just catch it from you?
August 20th, 2004, 04:08 AM
http://www.fawcette.com/javapro/archives/bs0999/ posted by chsh.
Well, my application works somehow similar like this.
I will briefly describe the classes in my application what it does:
If you're using an ATM to transfer funds between your savings and checking accounts, at some point, the amount being transferred is subtracted from one account (step 1) and added to the other (step 2).
Database.java, a generic database class used by all classes performing database operations.
NewController.java, a specific class responsible for creating a customer record.
Customer.java, this class contain all the sql statements for /insert/update/delete/select operations.
Account.java, this class contain all the sql statements for /insert/update/delete/select operations.
the flow of my application
my Servlet would request all the information from the jsp page. For example
In my NewController class, i will call the methods in the Customer and Account class
String name = request.getParameter("customerName");
String accountId = request.getParameter("accountId");
Customer customer = new Customer(name);
Account account = new Account(accountId);
NewController controller = new NewController(customer, account);
So in my Customer and Account class
public NewController(Customer c, Account a)
In this case, whenever i create a new customer record, i need to create a account for the customer as well. But in any of the scenario, it may be the creation of the customer record fail, or the creation of the account record fail, how should i alter the structure of my application ?
public void createCustomer()
Database db = new Database();
db.executeUpdate("insert into blah blah blah"):
Sorry for the bad english and my bad explanation