Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-21-2009, 06:10 PM
Member
 
Join Date: Dec 2009
Posts: 2
Rep Power: 0
cypher_girl is on a distinguished road
Default jsp insert into database error(java.lang.NumberFormatException: For input string: "")
Hi all,

I am trying to insert data from a jsp form into a table when the user clicks the submit button. I am encountering this exception.

java.lang.NumberFormatException: For input string: "type"

Here is my code:

This is the code in the form jsp:

<select name="utype">
<% try
{
while(rs2.next())
{
int type=(rs2.getInt(1));
String strName1=rs2.getString(2);
%>
<option value="type">
<%= strName1 %>
</option>
<%
}
}
catch(Exception e)
{
out.println(e);
}

%>
</select>

this is my code in the sign - up bean:

db.connect();

String firstName, lastName, address, city, state, email,userName, password, secAnswer;
int zipcode, phoneNo, utype, squestion;

firstName = request.getParameter( "firstName");
lastName = request.getParameter( "lastName");
address = request.getParameter( "address");
city = request.getParameter( "city");
state = request.getParameter( "state");
zipcode = Integer.parseInt(request.getParameter( "zipcode"));
email = request.getParameter( "email");
phoneNo = Integer.parseInt(request.getParameter( "phoneNo"));
userName = request.getParameter( "userName");
password = request.getParameter( "password");
utype = Integer.parseInt(request.getParameter( "utype"));
squestion = Integer.parseInt(request.getParameter( "squestion"));
secAnswer = request.getParameter( "secAnswer");

db.insert(firstName, lastName, address, city, state, zipcode, email, phoneNo, userName, password, utype, squestion, secAnswer);
response.sendRedirect("signupthanks.html");

and this is my dbBean's insert method:

public void insert(String firstName, String lastName, String address, String city, String state, int zipcode, String email, int phoneNo, String userName, String password,int utype, int squestion, String secAnswer) throws SQLException {
try {

PreparedStatement pstmt = null;
String queryString =
"INSERT INTO UserAccountDetails1(username,firstname, lastname, address, city, statecode, zipcode, email, phonenumber, password, usertypecode, questioncode, answer, lastmodifieduser, lastmodifiedtime) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

pstmt = dbCon.prepareStatement(queryString);
pstmt.setString(1, userName);
pstmt.setString(2, firstName);
pstmt.setString(3, lastName);
pstmt.setString(4, address);
pstmt.setString(5, city);
pstmt.setString(6, state);
pstmt.setInt(7, zipcode);
pstmt.setString(8, email);
pstmt.setInt(9, phoneNo);
pstmt.setString(10, password);
pstmt.setInt(11, utype);
pstmt.setInt(12, squestion);
pstmt.setString(13, secAnswer);
pstmt.executeUpdate();
pstmt.close();
} catch (SQLException sqlex) {
sqlex.printStackTrace();
}
}


thank you very much. any help is greatly appreciated.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-22-2009, 03:07 AM
Member
 
Join Date: Nov 2008
Posts: 8
Rep Power: 0
luckacc is on a distinguished road
Send a message via ICQ to luckacc Send a message via MSN to luckacc
Default
Quote:
<option value="type">
<%= strName1 %>
</option>
the value is 'type' ,not a int number,
so when cast the utype to int ,it throws exception .

Quote:
utype = Integer.parseInt(request.getParameter( "utype"));
correct code should be:
Quote:
<option value="<%= strName1 %>">
<%= strName1 %>
</option>[/
__________________
Just want to make friends to promote my English,would you like to make friends with me?
MSN:wanglongcai@hotmail.com

Last edited by luckacc; 12-22-2009 at 03:10 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-22-2009, 04:14 AM
Member
 
Join Date: Dec 2009
Posts: 2
Rep Power: 0
cypher_girl is on a distinguished road
Default
Thank you so much. I got in working.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 shantimudigonda New To Java 1 11-20-2009 08:58 PM
[newbie] Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: jon80 New To Java 3 06-07-2009 01:14 AM
How can I prevent "found void but expected java.lang.String" ? trueblue New To Java 3 05-21-2009 04:48 PM
Hi , Error in Jsp page is as "NumberFormatException.forInputString(Unknown Source)" lavanya82 JavaServer Pages (JSP) and JSTL 9 02-20-2009 08:22 AM
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException romina New To Java 1 07-25-2007 11:55 PM


All times are GMT +2. The time now is 11:59 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org