aspose file tools*
The moose likes JDBC and the fly likes NumberFormatException while inserting data into database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "NumberFormatException while inserting data into database" Watch "NumberFormatException while inserting data into database" New topic
Author

NumberFormatException while inserting data into database

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
In my project, I have created a functionality which registers Editors.
For this, I have used bean class, jsp, Servlet and a Dao class.

EditorBean.java







EditorServlet



EditorDao.java





Web.xml





AddEditor.jsp






I have a “Editors” table in database with following columns:
SQL> desc editors;


Name Null? Type
----------------------------------------- -------- ----------------------------
ID NOT NULL NUMBER(5)
USERNAME VARCHAR2(30)
PASSWORD VARCHAR2(30)
ADDR VARCHAR2(30)
CNO NUMBER(10)
EMAIL VARCHAR2(30)
AREA VARCHAR2(30)
DOJ DATE

<SQL>




On running the application using tomcat 6, I am getting exception with the following stack trace :
HTTP Status 500 -
________________________________________
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NumberFormatException: null
java.lang.Long.parseLong(Unknown Source)
java.lang.Long.parseLong(Unknown Source)
org.cmtes.Editor.Servlet.EditorServlet.doPost(EditorServlet.java:21)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.
________________________________________
Apache Tomcat/6.0.29


kunal
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Close all your input tags and retry.


[My Blog]
All roads lead to JavaRanch
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
i have tried that. but still, it showing the same error

I am inputing the following data:

Editor's Id : (Successfully Self generated)
UserName: kunal
Address: Samlong
Contact: 1234
E-mail id: abc
Area: Ranchi
Date of joining: (successfully Self generated)


Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

On your webpage, what's the value of your "t1" textbox ?
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
"t1" related to my id, which is self generated.

EditorDao





AddEditor.jsp






The id generated is 1001.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I mean, what is shown on your web browser ? Does the "Editor's Id" textbox show any value ?
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Yes, it shows 1001
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

What about "Contact" ("t5") ? Did you enter a value in it ?
Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

Kunal Lakhani wrote:
The id generated is 1001.


So rs.getString("ID") is null


http://serfj.sourceforge.net - Simplest Ever REST Framework for Java
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Eduardo Yañez Parareda wrote:
Kunal Lakhani wrote:
The id generated is 1001.


So rs.getString("ID") is null

But that is not a problem.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
yes Eduardo Yañez Parareda. That's only generating 1001.


Christophe Verré , yes i am entering values in t5, (value-123)
Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

Kunal Lakhani wrote:yes Eduardo Yañez Parareda. That's only generating 1001.


Christophe Verré , yes i am entering values in t5, (value-123)



Print us the correct stacktrace because what you printed doesn't correspond with the source code you posted. Line 21 from EditorServlet is commented out...
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

The cause for exception is seen at this line: org.cmtes.Editor.Servlet.EditorServlet.doPost(EditorServlet.java:21)

But its is commented out. Can you post the code which caused the exception?


Mohamed Sanaulla | My Blog
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Eduardo Yañez Parareda, The stack trace i printed is correct.
Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

Kunal Lakhani wrote:Eduardo Yañez Parareda, The stack trace i printed is correct.


I'm sorry, but it's impossible to have an exception caused in a commented out line...
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Eduardo Yañez Parareda wrote:
Kunal Lakhani wrote:Eduardo Yañez Parareda, The stack trace i printed is correct.


I'm sorry, but it's impossible to have an exception caused in a commented out line...


+1 here. Without the correct code we cannot tell the cause for that exception.
R Patel
Greenhorn

Joined: May 24, 2010
Posts: 13
Hi,

I can see one issue is, your "t1" field is disabled. so whenever your form is getting submit, that field value will not get submit. So i suggest you can take that value under hidden variable. and can change the below line to new as i have mentioned.

existing line:


replace above line with below lines.



Regards,
Ronak.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

I'm sorry, but it's impossible to have an exception caused in a commented out line...

The line numbering in this post doesn't neccessary match with the line numbering in the source file. Let's ask Kunal what the exact piece of code is where the exception is thrown.


Kunal, Can you tell us what this piece of code is in your original source file:
EditorServlet.java:21 ?

OCUP UML fundamental and ITIL foundation
youtube channel
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
I am confused friends.

The problem has been solved. What i did is, removed the commented line & closed MyEclipse IDE & started it again.
I don't know what is happening. At present, i am executing the same code, and its running fine. This is the 2nd time i am facing such problem. And if i am changing the code in MyEclipse, to make it to come into effect, i need to restart the IDE, its not getting refreshed while compiling it again

Can anyone tell the reason for same?
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Also, how to replace this scriptlets from EL in my jsp??

Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Kunal Lakhani wrote:Also, how to replace this scriptlets from EL in my jsp??



Please start a new thread for a new query
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

Although you've probably solved your current problem, a hidden bug is ticking in your code. It is lurking in the following line:

Never ever use the INSERT statement without specifying the columns into which you're inserting, for two reasons:

1) If the number of columns in the table is changed, your program suddenly stops working. If you specify the columns, and a new nullable column is added (or column with default value specified), the statement will remain functional. New columns may be added for various reasons (eg. auditing, replication) that are independent of your application.

2) The second reason is much more serious. The order of columns in the table is not necessarily fixed. If the table is recreated for some reason, or column is dropped and added again for any reason imaginable (including inept DB admin), the order of columns might change. If you're lucky, your program crashes with a data conversion error, or breaks an existing constraint. However, your code might continue to work, but insert data into columns different from what is intended. If this is not caught early on, your database might get littered with errorneous data that will be difficult to disentangle.
 
wood burning stoves
 
subject: NumberFormatException while inserting data into database