Forums Register Login

doubt using resultsets and queries in servlets

+Pie Number of slices to send: Send
Hi,

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???



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??
+Pie Number of slices to send: Send
The JDBC forum would be the perfect place to ask such a question.
If you ask them, you might want to tell them what Database you're using.
Some have transaction support, stored procedures, some don't. The answer you get will depend on these things.
+Pie Number of slices to send: Send
Although it do not belong to here, because its an SQL-problem.
I think you could not accomplish the task in one select/query.
It will be a row of selects/querys.
+Pie Number of slices to send: Send
I am going to move this to the JDBC forum.

Mark
+Pie Number of slices to send: Send
Yell,
Method "executeUpdate()", in interface "java.sql.Statement", returns the number of rows affected. Hence, if you try to update a non-existent row, method "executeUpdate()" will return 0 (zero). In that case, you can then safely insert a new row, otherwise you aree done! [Just a suggestion.]

Good Luck,
Avi.
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 973 times.
Similar Threads
Updateable ResultSet just for doing inserts: good idea?
Design question
Query two tables using hibernate
compare resultset values with string value
doubt in resultsets and queries in servlets
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:33:22.