This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes handling multiple queries with the same connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "handling multiple queries with the same connection" Watch "handling multiple queries with the same connection" New topic
Author

handling multiple queries with the same connection

satya sxy
Greenhorn

Joined: Mar 23, 2001
Posts: 13
Hello someone,
I am trying to use java servlets and jdbc for a project i am working on. I have a register servlet that does the registration part. When i submit this servlet,it should first check the database table if the username already exists ,if it exists then it do nothing. in case if the submitted username doesnt exist then the submitted information should be inserted into the database table. I tried doing this but i get erorrs. could someone throw light on this topic as to how to handle both the select query and insert query one after the other.
Any help, ideas, suggested readings are appreciated.
thanks,
shailu.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

algorithm:
connect
query the table for the username
if username does not exist
write to the database

I didn't compile the above code, but it should give you a start. As you can see, I prefer PreparedStatements over Statements in any situation that I can!
Jamie
satya sxy
Greenhorn

Joined: Mar 23, 2001
Posts: 13
Thanks jamie,
i will try this one.
I appreciate your help. thanks a lot.
shailu
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: handling multiple queries with the same connection
 
Similar Threads
sql
MySQL - add and remove username from table
Resetting Values
Validating Username and Password in JSP
AbstractTableModel