i want to convert string into integer

i have an html file in which i m using a text box , for entering amount i m using that text box entry at next jsp. i want to convert amount string into integer for further processing. At next jsp i m using:-

String amount= request.getParameter("bal");

Integer amount1 = Integer.valueOf((String)session.getAttribute("amount"));

and in sql query i m using amount1 as:-

ResultSet rs1 = st.executeQuery("update saving set balance = balance - amount1 where saving.account_no = '" + acc +"'");

my problem is i m getting following error:-

server encountered an internal error and

exception:- numberformat exception

please help me as soon as possible

[700 byte] By [ama_banka] at [2007-11-27 0:28:11]
# 1
Integer amount1 = Integer.valueOf((String)session.getAttribute("amount")).toString();
skp71a at 2007-7-11 22:29:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
> numberformat exceptionThis usually means that the given string is not in numeric format.What is it's value?
BalusCa at 2007-7-11 22:29:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

try {

String enteredAmount = request.getParameter("bal");

int amount = Integer.parseInt(enteredAmount);

}

catch (NumberFormatException e){

// entered value is not a number please try again...

// forward back to the page so that the idiot user can type it in properly.

}

Most frameworks will have support for this sort of feature.

evnafetsa at 2007-7-11 22:29:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

i hav used the code below in my jsp file to convert string into integer:

String enteredAmount = request.getParameter("bal");

int amount = Integer.parseInt(enteredAmount);

and i m getting followwing errors:-

1.The server encountered an internal error () that prevented it from fulfilling this request.

2.org.apache.jasper.JasperException: null

3.java.lang.NumberFormatException: null

these above problelems i m facing.....plz help me out as soon as possible.

ama.banka at 2007-7-11 22:29:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

null is not a number :)

Add a check on null.if (value != null) {

// convert number.

} else {

// error: value is null.

}

BalusCa at 2007-7-11 22:29:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

i have used following lines in my code:-

1. String amount= request.getParameter("bal");

2. Integer amount1 = Integer.valueOf((String)session.getAttribute("amount"));

user enters any number in text box "bal"

and i want to convert that string into integer , i m using amount1 in following query:-

ResultSet rs1 = st.executeQuery("update saving set balance = balance - amount1 where saving.account_no = '" + acc +"'");

i again got the number format exception in line 2.

please suggest me wht should i do?

ama.banka at 2007-7-11 22:29:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
i still getting number format exception in line 2:-String amount= request.getParameter("bal"); Integer amount1 = Integer.valueOf((String)session.getAttribute("amount"));now what should i do?
ama_banka at 2007-7-11 22:29:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

> i still getting number format exception in line 2:-

> String amount= request.getParameter("bal");

> Integer amount1 =

> Integer.valueOf((String)session.getAttribute("amount"

> );

> now what should i do?

Again: you just need make sure that the String value you're going to put into a Number is also really a number. That is: not null, not empty, no spaces, at least one digit and no another characters.

BalusCa at 2007-7-11 22:29:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...