Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Column can not be null

 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all following is my sql insert into query and its throwing Column can not be null Exception. Please help

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure none of the values you're about to insert is null. The most likely candidate seems "bb", but you should check all of them, either by adding logging statements, or by attaching a debugger.
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Make sure none of the values you're about to insert is null. The most likely candidate seems "bb", but you should check all of them, either by adding logging statements, or by attaching a debugger.


Thanks for your reply. As you said, I have checked everything and none of them is being passed as null and this is what I got

java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'null(topic,question,a1,a2,a3,a4,hint_pic,date)values(null,null,null,null,null,nu' at line 1
am not able to figure it out please help.
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All I am able to understand from this is request.getParameter is not working. What can be done now?
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also I think that bb may not be the problem because when I wrote



like



and the query worked and did insert the data.
therefore I think request.getParameter(), is that the problem?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, like I said, you need to check all the parameters. That particular one was just a guess.

Edit: After reading the other replies as well:

All I am able to understand from this is request.getParameter is not working.

How can getParameter not work? You said you checked all the parameters, and that they were getting to the servlet OK... ?
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ummm!! oh yeah i mean!! you are right..!! See how freaked I'm now.!! Please tell me. See I have checked all the parameters and have also compared with other similar type of code which is working. But still not able to find any issues. I'm posting my JSP page's code also. Please have a look for me.

create_test.jsp



add_test.java Servlet

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some comments in no particular order:

The rs.beforeNext() statements in lines 32 and 47 of the JSP don't accomplish anything, and neither do the import statements in line 1 and 2.

You should not have Java code in JSPs - read up on the MVC pattern, and start implementing it.

You don't need to load the DB driver every time you make a DB call. In fact, you shouldn't. Move that code to a servlet context listener class.

You should close DB connections once you're done with them.

The likely problem is the fact that the file upload library alters the parameter handling, and you need to take a different approach. Search for "Process a regular form field" in http://commons.apache.org/proper/commons-fileupload/using.html.
But if that's the issue I'm confused - you said you checked that the parameters are getting to the server OK, right? So all the variables in lines 56-62 of the servlet had correct values, yes?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic