• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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: 43011
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: 10
  • 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?
 
Whatever. Here's a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!