aspose file tools*
The moose likes JDBC and the fly likes Passing values from select element (html) to servlet to a DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Passing values from select element (html) to servlet to a DB" Watch "Passing values from select element (html) to servlet to a DB" New topic
Author

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

Luis Villamarin
Greenhorn

Joined: May 24, 2012
Posts: 21

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

Joined: Jun 05, 2010
Posts: 622
First of all, why would you want to insert the account type as int?


Does resolves to an int or a String?


kunal
Luis Villamarin
Greenhorn

Joined: May 24, 2012
Posts: 21

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

Joined: Oct 21, 2008
Posts: 1107

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

Joined: May 24, 2012
Posts: 21

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

Joined: Jun 05, 2010
Posts: 622
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Passing values from select element (html) to servlet to a DB