This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes not able to insert a null value in the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "not able to insert a null value in the database " Watch "not able to insert a null value in the database " New topic

not able to insert a null value in the database

jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
when i try to insert a null value in the database.. the jsp page gives an error that javax.servlet.ServletException: For input string: ""
even though i have put option as null in sql server for the values 'number' and 'vol_no'. here is the code iam using:
<%@ page language="java" import="java.sql.*,*" %>
Connection con=null;
java.sql.Statement stmt=null;
String paper_title="";
String authors="";
int type=0;(type is the name of the radio button)
String name="";
int vol_no=0;
int number=0;
int year=0;
String xy=(String)session.getAttribute("y");
System.out.println("the value of paper_title is:"+paper_title);
System.out.println("the value of authors is:"+authors);
System.out.println("the value of type is:"+type);
System.out.println("the value of name is:"+name);
System.out.println("the value of vol_no is:"+vol_no);
System.out.println("the value of number is:"+number);
System.out.println("the value of year is:"+year);
con=DriverManager.getConnection("jdbc dbc:mech_iit");

int i=stmt.executeUpdate("insert into publications(user_login,paper_title,authors,type,name,number,vol_no,year) values('"+xy+"','"+paper_title+"','"+authors+"',"+type+",'"+name+"',"+number+","+vol_no+","+year+")");


catch(Exception e)


where could be the error..
Joe Ess

Joined: Oct 29, 2001
Posts: 9169

Doesn't sound like a database or JDBC problem. Sounds more like you are getting an exception processing the page request. Like when you try to parse a blank as a number:

If either of these parameters are not a number a NumberFormatException will be thrown.

[How To Ask Questions On JavaRanch]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32844

Also, be careful with null strings. 'null' is not the same as null.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: not able to insert a null value in the database
It's not a secret anymore!