Solved

How to convert Integer value to String Value in JSP?

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now