• 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

not able to insert a null value in the database

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.*,java.io.*" %>
<%
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");
if(xy==null)
xy="jyotsana";
paper_title=request.getParameter("paper_title");
authors=request.getParameter("authors");
type=Integer.parseInt(request.getParameter("type"));
name=request.getParameter("name");
vol_no=Integer.parseInt(request.getParameter("vol_no"));
number=Integer.parseInt(request.getParameter("number"));
year=Integer.parseInt(request.getParameter("year"));
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);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:mech_iit");
stmt=con.createStatement();

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+")");

stmt.close();

con.close();
}
catch(Exception e)
{
System.out.println(e);

}
%>

where could be the error..
thanks
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
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
Also, be careful with null strings. 'null' is not the same as null.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic