• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet & JDBC connection

 
induz sat
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have UserRegistration servlet that fetches parameters from register.jsp and add records to RegisteredUser db through JDBC on Tomcat.

what is wrong in the code as when i run the jsp it shows all the elements of HTML form. but when i type in something in TextBox and submit it, Tomcat says "you are not connected to the internet". I can visit yahoo though from the same webbrowser. Also it does not add any records in RegisteredUser table.



 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Impossible to say without seeing the entire code. I notice that you have a curly closing brace in line 6 - is that a typo, or a bug in the program?
 
Raj Chila
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Ulf Dittmer, there could be a lot of reasons why you see that error...but just by looking at your code snippet, Should'nt you be using a Prepared Statement? and if you are not, then the ?'s should be replaced with actual values and the value key word needs to be values.
 
induz sat
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
curly closing brace in line 6
was a typo. Corrected.

Could you please suggest a working link/example example of PreparedStatement generic class and its methods.

Thanks a lot...I can check a record in the same db in the same project through a Login.jsp and LoginServlet. Do I have to close the jdbc connection for another doPost method to connect??

Thanks again



 
Santhosh ayiappan
Ranch Hand
Posts: 80
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the resources like Statement, Connection should be closed in the finally block.

You have to use the execute or executeUpdate method to perform the insert operation.

executeQuery ExecuteQuery should be used for the Select
 
Li Qiangqiang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"INSERT INTO SocialNetwork.REGISTEREDUSER (Name,Password,Age) values (?,?,?)"
 
Rajesh Vassey
Greenhorn
Posts: 8
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you paste the Tomcat server logs. Which can make us know some more insights of error?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic