• 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

Facing Problems in inserting data into database in jsp

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created few input boxes and a submit button to insert values into database. this is my entire code:-



Now the problem is that in the following part data doesn't get assigned to the values.. as a result it is always showing null.. i have tried to directly put the values in the insert line then it takes the values....



here dob,supplier...etc does not get the parameters. What to do??


 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, first off none of this code should be in a JSP page.
It belongs in a Servlet...well, actually it belongs in a service or similar that the servlet calls, so it can be tested easily in isolation.

None of that code you have at the moment can be tested to ensure it is logically correct, without deploying it to a server.
It's also so tightly tied into the HTML side of things I'm surprised you can follow what's going on.

The immediate thing with the bit of code you highlighted is that, if those other fields aren;'t being populated then "receive" must be null.
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Well, first off none of this code should be in a JSP page.
It belongs in a Servlet...well, actually it belongs in a service or similar that the servlet calls, so it can be tested easily in isolation.

None of that code you have at the moment can be tested to ensure it is logically correct, without deploying it to a server.
It's also so tightly tied into the HTML side of things I'm surprised you can follow what's going on.

The immediate thing with the bit of code you highlighted is that, if those other fields aren;'t being populated then "receive" must be null.



yes clicking receive means it isnt null. The main problem is that request.getparameter isnt working.. I have tried to put direct values and it was getting into the database then. But when i am taking input values it is showing null?? Something with the form tag???
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is because you have too much stuff going on on this page.
You really need to get that code out of there, it is confusing the issue.

Are you sure the correct data is being sent in the request?
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:This is because you have too much stuff going on on this page.
You really need to get that code out of there, it is confusing the issue.

Are you sure the correct data is being sent in the request?



I am directly pasting the parts.. You just have a look....

Now


Have a look here.. Maybe i have got some errors in other parts.. But i cant get the error.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That doesn't say whether the correct data is being sent in the request.

To do that you need to look at the request itselfd, which will involve using the developer tools for your browser (usually F12).
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:That doesn't say whether the correct data is being sent in the request.

To do that you need to look at the request itselfd, which will involve using the developer tools for your browser (usually F12).


srry didnt knew it

anyway can you explain it? I pressed f12.. I can see the code in the elements section.. Now what???
 
Rancher
Posts: 517
15
Notepad Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try this (just for testing) and see what is happening with the OUTPUT (I have removed the database related code and kept most of the other stuff as it is) :

 
Dave Tolls
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There will be a Network see requests.
Selecting the relevant request will give let you see what parameters were sent.

ETA:  However, I will again point out that the Java code has no place in that JSP page.
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Saya wrote:You can try this (just for testing) and see what is happening with the OUTPUT (I have removed the database related code and kept most of the other stuff as it is) :





Bro Its printing what i am inserting only... type is not printing... Maybe because of the div class?
 
Dave Tolls
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That <div> in the type input is a typo.
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:That <div> in the type input is a typo.


Whatever I got that.. It is printing.. Then what was the mistake in the original code??
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone... I think that div part in type was making a problem.. Now that its fixed. The values are being accepted by the parameters.. But CAN YOU ALL TELL ME HOW TO CHANGE THE DATE FORMAT... My dataBase accepts date in the format yyyy-mm-dd but the html datapicker takes values in the format dd/mm/yyyy.. Any way to change this ??
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mayukh Singha Roy wrote:Thanks everyone... I think that div part in type was making a problem.. Now that its fixed. The values are being accepted by the parameters.. But CAN YOU ALL TELL ME HOW TO CHANGE THE DATE FORMAT... My dataBase accepts date in the format yyyy-mm-dd but the html datapicker takes values in the format dd/mm/yyyy.. Any way to change this ??


Although I changed the date format in database to varchar and its working but any other way of implementing this?
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't store a Date in the DB as a String.
It's a date, so store it as one.

As for formatting the date, there are date formatting classes depending on which date you are using (ie, is it the old Date class or the newer date time package?).

And why the old thing didn't work?
Who knows, since you never posted the HTML we were asking for.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic