|
-
May 7th, 2001, 09:04 AM
#1
Thread Starter
New Member
Java Bean & database connectivity
I have a shopping cart bean that holds an array for the 'id', 'description', 'quantity', and 'price' for all items added to the cart. I am able to display the information on a web page, but I don't know how to get it from the cart bean to a database. I am using JSP. Any help would be great!
-
May 7th, 2001, 12:04 PM
#2
Lively Member
hey vgdid,
assuming that you have id, description, quantity, and price, you could do it numerous ways:
1) best way is to get up a seperate bean files...
one bean would have a connection pooling properties...
this bean would manage all the users who put items onto a respect cart for that session. Session tracking comes into play here. Once a person logs on and decides to purchase the items, just a prepared statement.
something like this....
private PreparedStatement stmt = con.prepareStatement("INSERT INTO tablename "+"VALUES (?, ?, ?, ?)";
.
.
.
stmt.setInt(1, id);
stmt.setString(2, description);
stmt.setInt(3, quantity);
stmt.setDouble(4, price);
stmt.executeUpdate();
This is procedure for inserting a single item from the cart. You would have to set it in a loop if there are multiple items in the cart. PreparedStatements are preferred over creatStatements because they are already compiled code so the database handles the sql statments faster. You will not notice it if you have one or two items randomly, but if you have 15+ users making 3 to 4 items every few minutes time gets to be a big factor.
I think this is what you are looking for...
there is a broad review of jdbc...here is a link to it
http://java.sun.com/docs/books/tutor...ot0/index.html
Manoj
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|