Jump to content

JAVA vs DATABASE DATA TYPE

- - - - -

  • Please log in to reply
7 replies to this topic

#1
mutago

mutago

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
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

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
If you're reading an integer from your database, shouldn't you store it in an integer data type in Java?

#3
mutago

mutago

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
please illustrate with example as i don't understand what u mean
thanks

#4
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
gregwarner is saying you need to define your variable as an int instead of a string.

string Amount = "abc";
int am = 1;


#5
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
That's right. You had written:

string Amount=request.getParameter("Amount");

when I think you probably meant:

int Amount=request.getParameter("Amount");



#6
mutago

mutago

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
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

#7
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Ahh, so that "request" is a HttpServletRequest?
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
arnie137

arnie137

    Newbie

  • Members
  • Pip
  • 2 posts
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);




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users