Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

handling multiple queries with the same connection

 
satya sxy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks jamie,
i will try this one.
I appreciate your help. thanks a lot.
shailu
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic