• 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

Passing values from select element (html) to servlet to a DB

 
Greenhorn
Posts: 21
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

In my database I have a int field called accountType. The data to be stored in that field is coming from select element (html) with different 3 different options as follows:


I have a servlet that gets the parameter from the html elements. For a string I know I have to use something like , However I'm a little confused about how to get the selected option value as an int so I can store it as int using a DB class.

I will appreciate any suggestions on how to approach this.

Thanks in advance.

 
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, why would you want to insert the account type as int?


Does resolves to an int or a String?
 
Luis Villamarin
Greenhorn
Posts: 21
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kunal thanks for the response.

I have changed that to a string now. However, I would still like to ask you how to pass an integer from form to a servlet to a DB?

Thanks in advance.

Luis
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is in reality 2 seperate questions
1 how to get the information from a form to a servlet
2 how to then get that data into the DB.

So I have 2 answers:
1, Have you done any reading on jsp and servlets, I would recommend the head first servlets and JSP book is a good starting place there.

2, And have you done any jdbc work at all? as this is pretty basic stuff so should be covered in any basic level tutorial.
 
Luis Villamarin
Greenhorn
Posts: 21
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Wendy – Thanks for the suggestion. I thought there was something specific to servlets to pass int values.

I solved the issue using the regular Integer.parseInt.

In case others have the same question this is what I did:


Thanks again.

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Luis Villamarin, that was a basic java stuff.

This is in reality 2 seperate questions
1 how to get the information from a form to a servlet
2 how to then get that data into the DB.

So I have 2 answers:
1, Have you done any reading on jsp and servlets, I would recommend the head first servlets and JSP book is a good starting place there.

2, And have you done any jdbc work at all? as this is pretty basic stuff so should be covered in any basic level tutorial.



Luis Villamarin, i agree with Wendy Gibbons. It would be better if you go through head first servlets and JSP book
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic