Win a copy of Getting started with Java programming language this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
charless robinson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36171
439
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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?
 
Junilu Lacar
Sheriff
Posts: 10754
151
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Paul Clapham
Sheriff
Posts: 22127
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
Ron McLeod
Saloon Keeper
Posts: 1359
193
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Marshal
Posts: 36171
439
Eclipse IDE Java VI Editor
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!