Solved

How to convert Integer value to String Value in JSP?

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

Industry Leaders: 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

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

707 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