Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to convert Integer value to String Value in JSP?

Posted on 2001-08-26
4
Medium Priority
?
1,511 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 300 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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:
Suggested Courses

610 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