• 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
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Facing Problems in inserting data into database in jsp  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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??


 
Master Rancher
Posts: 3676
40
  • Mark post as helpful
  • send pies
  • 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
  • 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
Master Rancher
Posts: 3676
40
  • Mark post as helpful
  • send pies
  • 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
  • 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
Master Rancher
Posts: 3676
40
  • Mark post as helpful
  • send pies
  • 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
  • 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: 506
15
Java Notepad
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Master Rancher
Posts: 3676
40
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
Master Rancher
Posts: 3676
40
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
Master Rancher
Posts: 3676
40
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!