-
JDBC PreparedStatement
I have to retrive the details of purchase bill and the database design is bill number is primary key and foreign key for bill items and each item in bill maintains other charges independently
how to write a prepare statement so that retrieve one row in purchase bill
multiple rows of item in a bill and other charges for each item
-
there is a good tutorial about database connectivity that covers also prepared statements here in this forum. click it ...
-
Probably three queries.
One to get the bill.
One to get the bill items for that bill.
One to get the charges for each bill item.
That'll result in multiple hits on the db, which may or may not be a problem, that's for you to determine.
These can be squeezed together, getting the bill data and the items in one go, then all the charges in a second go, but that can look messy (you'd be getting multiple copies of the bill data for example, and you'd need some logic to extract the correct set of charges for a particular item).
If your system is already modular, that is you have a BillDao, a BillItemDao and a BillItemChargesDao, then the former is the neater solution, albeit with more db traffic.