• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to insert values in database

 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
data is not inserting the database.


please help in resolving this problem
 
Rancher
Posts: 989
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.) Do not have empty catch blocks. You are probably hiding an exception which is making the data not insert.
2.) Do not write code that connects to databases in JSPs. Use a servlet for that (or a normal class which you call from the servlet). JSPs should be used for presentation only not for processing.
3.) Use a PreparedStatement to set parameters to guard against SQL injection.
 
Ranch Hand
Posts: 49
1
Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there an error? is your out.println printing the message? is lang[] coming in as a non-null param?

I am expecting a NullPointerException.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

krishna kanth wrote:Is there an error? is your out.println printing the message? is lang[] coming in as a non-null param?

I am expecting a NullPointerException.



yes,you are right null pointer exception is coming.
how can i remove this?
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should avoid putting code in jsp as suggested by E Armitage. However to resolve this particular issue, you may wish to try this

 
Krishna Kanth
Ranch Hand
Posts: 49
1
Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see you just started practicing JSP's, but you would need to follow guidelines Armitage mentioned above.
First thing move the code off JSP to a servlet or server side java class to execute the logic, which will show you the problem clearly.


Are you expecting a lang to be saved to DB, when you access this JSP by URL? lang would get saved to DB only when you submit this page.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
now this is printing "No data found to be inserted "
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means you are not getting any values from the page (from where you are submitting the details) to this jsp page.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

krishna kanth wrote:I see you just started practicing JSP's, but you would need to follow guidelines Armitage mentioned above.
First thing move the code off JSP to a servlet or server side java class to execute the logic, which will show you the problem clearly.


Are you expecting a lang to be saved to DB, when you access this JSP by URL? lang would get saved to DB only when you submit this page.


ok. i'll first convert into servlet and jsp and then try to insert the values in the database.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:It means you are not getting any values from the page (from where you are submitting the details) to this jsp page.



yes
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code shouldn't be doing any of the DB stuff unless the "lang" parameter actually exists. (Any yes - once you implement all the advice given above, the DB stuff will not longer be part of the JSP, so the issue is moot.) My guess is that you're accessing this JSP directly - in which case no parameter is passed.
 
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is there a need to use

As there is no multiple=true in your select tag. You can only select one value from the combo.

And catch more specific exceptions in catch block then catching all exceptions at once using a general Exception class.
 
reply
    Bookmark Topic Watch Topic
  • New Topic