Solved

How to convert Integer value to String Value in JSP?

Posted on 2001-08-26
4
1,494 Views
Last Modified: 2008-02-01

  Hi, i'm new with JavaServer Page(JSP), and i want to do some increasing number as the ID number for employee records. below is the case and problems found:

1.in the Page1.jsp
  select * from employee order by(ID) desc

if (rs!=null){
int id=getInt("ID)
int id2=id+1 //to increase a number for a new employee
print.out("New ID:"id2);
}
else
id2=10000;
}

2. in the Page2.jsp

String id=rs.getParameter("id2");
String name=rs.getParameter("Name");
"insert into employee(id, name)values(id2,'"+name"'")");

Error Message: Can't convert Integer to String

So, can you show me how to solve this problem?



0
Comment
Question by:sushifish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 6

Expert Comment

by:kotan
ID: 6427403
Should be

"insert into employee(id, name)values(" + id + ",'"+ name + "')"

The variable is id not id2.
0
 
LVL 1

Expert Comment

by:LDC
ID: 6428006
Use Integer.parseString method or something like this.
0
 

Accepted Solution

by:
raviraj_rao earned 100 total points
ID: 6428508
The getParameter takes always gets the variable as a string. So once you have the parameter as a string you can explicitly convert it into a integer by Integer.parseInt("String") and assigning this value to an integer varibale.
The better method is to use the oracle to your advantage. instead of just inserting the id convert it into a number by giving "insert into employee (id,name) values(to_number("+id+"),"+name+")";
The best method would be not to calculate the id in your application, where as create a sequence number in oracle eg:EMP_SEQ and just give EMP_SEQ.NEXTVAL in your insert statement in the place of "id" this will reduce a lot of overhead on you to keep track of the id and also makes the application simple.
Hope this answers your question.
0
 

Expert Comment

by:hanumansetti
ID: 6428619
Create Sequence number(EMP_SEQ) on employee table and write database trigger (ON INSERT - inserting a new record use sequence number EMP_SEQ.NEXTVAL).

Otherwise, rs.getParameter("id2").toString();
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question