| Author |
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.*,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
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8259
|
|
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.
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26144
|
|
|
Also, be careful with null strings. 'null' is not the same as null.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: not able to insert a null value in the database
|
|
|