aspose file tools*
The moose likes Servlets and the fly likes help me with insert and select query in Jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "help me with insert and select query in Jsp" Watch "help me with insert and select query in Jsp" New topic
Author

help me with insert and select query in Jsp

joseph xavier
Greenhorn

Joined: Feb 01, 2001
Posts: 13
I have a table with 2 fields - viz product code and product name. The product code which is the primary key , is autonumbered . My jsp page executes a method in bean A which inserts the product name into the table. And my next line of code calls another method of bean B which queries the same table to get the code number of the product that has been inserted.
The problem is the jsp page is not able to get the desired results that i.e. bean B is not able to query the data base successfully. The is so because the query , though the method is called afterwards, tries to query the table for the record before the insert statement in executed. When I check the database, the record is inserted into the table.I have arrived at this conclusion because , when the page is refreshed the query is executed . Probably this gives time for the inserted statement of bean A to the executed before the query statement of bean B is called.
I have also tried to call the method of bean B in bean A .
Kindly help me get over this problem as i need to know the product code immediately after the insert statement
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by josxavier:
[...] My jsp page executes a method in bean A which inserts the product name into the table. And my next line of code calls another method of bean B which queries the same table [...] though the method is called afterwards, tries to query the table for the record before the insert statement in executed. When I check the database, the record is inserted into the table.

If you used two different Connection objects, the database may not show you the result of your insert until you have actually committed the transaction.
Could this be the problem?
- Peter
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"josxavier",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help me with insert and select query in Jsp
 
Similar Threads
execute() method doesn't execute.
Issue with Hibernate transaction in CMT
how to get the inserted record by using resultset in java?
Getting duplicate records when the page refreshes.
A doubt with triggers