• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Luis Villamarin
Greenhorn
Posts: 21
Android Chrome Java
  • Mark post as helpful
  • send pies
  • 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.

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic