Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

doubt in resultsets and queries in servlets

 
Yell Srik
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

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
Posts: 287
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.

regards,
Tualha Khan
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34195
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.

Thanks
Jeanne
JDBC Forum Bartender
 
    Bookmark Topic Watch Topic
  • New Topic