Good day everyone, i need assistance. To get a value from a form field eg name i used string name=request.getParameter("name"); this is because the datatype is varchar but
if the datatype is integer how do i use it in the code. i tried this
string Amount=request.getParameter("Amount"); but its not working because am using amount to perform calculations. How do i make this datatype for amount right
thanks
7 replies to this topic
#1
Posted 21 March 2011 - 12:23 PM
|
|
|
#2
Posted 21 March 2011 - 01:24 PM
If you're reading an integer from your database, shouldn't you store it in an integer data type in Java?
#3
Posted 21 March 2011 - 01:39 PM
please illustrate with example as i don't understand what u mean
thanks
thanks
#4
Posted 21 March 2011 - 01:42 PM
gregwarner is saying you need to define your variable as an int instead of a string.
string Amount = "abc"; int am = 1;
#5
Posted 21 March 2011 - 01:56 PM
That's right. You had written:
string Amount=request.getParameter("Amount");
when I think you probably meant:
int Amount=request.getParameter("Amount");
#6
Posted 21 March 2011 - 02:24 PM
okay for You to understand my point. I have worked with java swing but wants to migrate some parameters and variables to servlets.
In my swing i have this
string stri1
int int1
str1=textfield2.getText(); // gets amount
int1=Integer.parseInt(str3);
Now how do i write this in servlet or jsp
i wrote it this way
string stri1
int int1
str1=request.getParameter("str1");; // gets amount
int1=Integer.parseInt(str3);
varible str1 is representing amount which has integer datatype in the database. please correct me in jsp/servlet
thanks
In my swing i have this
string stri1
int int1
str1=textfield2.getText(); // gets amount
int1=Integer.parseInt(str3);
Now how do i write this in servlet or jsp
i wrote it this way
string stri1
int int1
str1=request.getParameter("str1");; // gets amount
int1=Integer.parseInt(str3);
varible str1 is representing amount which has integer datatype in the database. please correct me in jsp/servlet
thanks
#7
Posted 21 March 2011 - 11:28 PM
Ahh, so that "request" is a HttpServletRequest?
Then first try
If that didn't work, do it like you did.. I don't see a problem there, unless the fact that you should parse str1 instead of str3 in your code, but I guess that's a typo.
Then first try
int1 = (Integer) request.getAttribute("str1");
getAttribute does the same as getParameter, but returns it as an Object instead of a String.If that didn't work, do it like you did.. I don't see a problem there, unless the fact that you should parse str1 instead of str3 in your code, but I guess that's a typo.
#8
Posted 21 March 2011 - 11:37 PM
Hello
You can load integer from database without any external parsing method
For load Integer from database use command
rs object of ResultSet
int a=rs.getInteger(ColumnName);
You can load integer from database without any external parsing method
For load Integer from database use command
rs object of ResultSet
int a=rs.getInteger(ColumnName);
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top










