Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

howto save multi line items data ?

 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, can someone pls guide how to save multi line item in form into DB ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"multi line"? Not sure what you mean by that. Everything in a form will be in some named form element. You can get the contents of these elements in a Servlet by getting them from the request by name. You can persist them using JDBC.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you looking for CLOB. But it is for really long objects. However, you can use the same, VARCHAR.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, imagine that we have a form which have multiple line items, let's assume we have fields in form like product.no , item description, price and quantity , line item means each line that describe for single product or good sold ,

example :

product no | qty | item desc | price
p1 | 10 | product1 | 9
p2 | 20 | product2 | 10

here , table shown 2 line items

how we save say we have many line items to DB ?
[ February 21, 2005: Message edited by: Alvin chew ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this by appending the row number to the name attribute of each field;

product_id_1
quantity_1
price_1

product_id_2
quantity_2
price_2

Also, write a row_count variable to the page in a hidden form field.


Then in your servlet you can loop through the values to build your data structure (2D array or whatever).



You'll then have a nice 2D array that you can pass to your database bean.

In your bean, you can just as easily loop through this array and perform an update for each row.

NOTE: You'll want to deal with a possible non-numeric value coming from the row_count parameter by catching a NumberFormatException.

Also, when looping and performing updates on each iteration, a PreparedStatement will be much more efficient than a regular statement.
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/PreparedStatement.html
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JDBC forum.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for answering
howto set rowcount correctly ? how we detect how many itemsline already set ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic