• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java and database data type

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day. I have worked with java swing but wants to migrate some parameters and variables to servlets.
In my swing i have this


Now how do i write this in servlet or jsp
i wrote it this way but its not working

varible str1 is representing amount which has integer datatype in the database. please correct me in jsp/servlet
thanks
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you would never write this in a JSP because it is not acceptable to put Java code in a JSP, so I'll move this to the Servlets forum.

Please explain exactly what "not working" means.
 
muntago Richard
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
below is a swing code

which means that am trying to get a form field from textfield2 hence
str1=textfield2.getText(); and the form filed am trying to get has interger datatype hence
int1=Integer.parseInt(str1);


In servlet, how do i write this, i try putting it this way but it errored

thanks
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

muntago Richard wrote:i try putting it this way but it errored


How?
 
muntago Richard
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem is here
str1=textfield2.getText();

in servlet i entered this
str1=request.getParameter("str1");
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
We do not know what exception you faced.
But make sure you are getting "str1" as a request parameter and it is not null.
If you pass any non-numeric value in this request parameter then you will get NumberFormatException too. To avoid this you should validate for the "str1" if its numeric.

Regards,
amit
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Continuing to keep us guessing as to what error you are getting will only delay any help further.
reply
    Bookmark Topic Watch Topic
  • New Topic