• 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

I'm trying to insert data into the database, however it displays "null"

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone.....I'm new to programming. Please help me out with this issue.

It is accepting the values however, Database doesn't show the actual given data. displays as "null"

JSP


HTML code
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

You say it is accepting the values. Does that mean if you add a print before this line, the four values aren't null?
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

You really shouldn't be doing any kind of database access in a JSP. If you're following an example from a book, I'd suggest you get another book. That way of programming JSPs was way back in the very early days of Java.

I'm adding this thread to the JSP forum. Sheriff Bear will be around shortly to put you on the right path.
 
charless robinson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Jeanne Boyarsky,Junilu Lacar.. Thank you for your reply.

The String values are given in HTMl page. I did not understand why the DB is showing null values. Its my school assignment.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm surprised that you are getting records written to the database at all, since that JDBC URL looks wrong to me. But if that code is actually adding rows to the database and the values in the rows are all null, then that inevitably means that your code put the nulls there. Jeanne suggested you should put some debugging code into your JSP to see if that's really the case -- I second that suggestion.
 
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your input elements are missing a name attribute.  Read-over this explanation of the HTML <input> name attribute.

If you would like to test your HTML form independently of the JSP code, try specifying an action of http://httpbin.org/post in your form.  httpbin is a test site and it will return back informaiton about your request (in JSON format).  What would be interesting for your particular problem is what it returned in the JSON form attribute.

For example - I added another input element to your form.


If I enter Hello HTML in to my new element and submit the form to httpbin, I get this back:

In the form attribute there is one key/value pair: the key is what I specified as the name in my new input element; and the value is what I entered in the my new field in the form.  As you have already know, to get this value in JSP, you would use request.getParameter("another-field-for-testing").

My suggestion: add the missing name attributes to your input elements, test with httpbin until the form is working as expected, then try with your JSP code again.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good catch Ron!
reply
    Bookmark Topic Watch Topic
  • New Topic