This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
i am reposting this question that i initially posted in 'Servlets' forum..
i am writing a code that involves JDBC-ODBC in servlets. the place where i am currently stuck is:
i have a table named emp with 4 columns: name,title,city and country
now i need to write a query that first checks if the table is empty. if empty, new values are entered into the table. if the new data (entered by the user) already exists, the old values in the emp table should be overwritten by the new values.
how can this query be written???
{ i am using MS-Access as the database)
PS: the logic i have thought of (but finding it difficult to implememt) is that: first use the query "select * from emp" and assign the results to a ResultSet (say rs1). now we can check the contents of rs1. if empty, the insert statement can be written else an update statement is written.. will the above logic work and if yes, how to write such a code??
Tualha Khan
Ranch Hand
Joined: Nov 22, 2000
Posts: 287
posted
0
a better option would be to check if the table contains 'that specific employee record', if yes, then update 'that particular employee record', if not, then insert 'that particular employee record'.
going by your logic,
if the result set is not empty, then you will be trying an update, but look, the resultset has some rows, but that specific employee record which you want to update does not exist, so the update should fail.
that's just my opinion, lets see what others have to say.
Yell, Please continue discussion in the original thread, which has since been moved to this forum. In the future, don't cross-post the same question. Just ask a bartender/sheriff to move it for you.