Solved

How to convert Integer value to String Value in JSP?

Posted on 2001-08-26
4
1,489 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
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

809 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