• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

servlet & JDBC connection

 
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.



 
Rancher
Posts: 43016
76
  • 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?
 
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



 
Ranch Hand
Posts: 81
Eclipse IDE Oracle Java
  • 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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"INSERT INTO SocialNetwork.REGISTEREDUSER (Name,Password,Age) values (?,?,?)"
 
Greenhorn
Posts: 8
Hibernate Spring Java
  • 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?
 
Your mind is under my control .... your will is now mine .... read this tiny ad
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic