Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to insert values in database

 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
data is not inserting the database.


please help in resolving this problem
 
E Armitage
Rancher
Posts: 989
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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.
 
Krishna Kanth
Ranch Hand
Posts: 49
1
Chrome Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • 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
Chrome Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
now this is printing "No data found to be inserted "
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • 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.
 
Ishan Pandya
Ranch Hand
Posts: 226
Java
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic