By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,403 Members | 1,275 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,403 IT Pros & Developers. It's quick & easy.

Java Integer question involving JSP/HTML FORM

100+
P: 108
Greetings,

Within my jsp I have HTML code (see below) which accepts input, one of these fields sequence unlike the others is an Integer.

Expand|Select|Wrap|Line Numbers
  1. <FORM ACTION="wk465682AddFAQ.jsp" METHOD="POST">
  2.   Id: <INPUT TYPE=TEXT NAME=Id><BR><BR>
  3.   Category: <INPUT TYPE=TEXT NAME=category><BR><BR>
  4.   Question<BR><TEXTAREA NAME=question COLS=100 ROWS=2></TEXTAREA><BR><BR>   
  5.   Answer<BR><TEXTAREA NAME=answer COLS=100 ROWS=4></TEXTAREA><BR><BR> 
  6.   Sequence: <INPUT TYPE="int" NAME=sequence><BR><BR>       
  7.   <INPUT TYPE=Submit VALUE="Add to Database">
  8. </FORM>
These values are then retrieved in the same jsp file using the code below and inserted into the table (sequence field in a Number in MS acess):-

Expand|Select|Wrap|Line Numbers
  1. Enumeration parameters = request.getParameterNames();
  2.  
  3.  if(parameters.hasMoreElements()) {
  4.     String IdParam  = request.getParameter("Id");
  5.     String categoryParam  = request.getParameter("category");
  6.     String questionParam = request.getParameter("question");    
  7.     String answerParam = request.getParameter("answer");    
  8.     Integer sequenceParam = request.getParameter("sequence");
  9.     statement.executeUpdate("INSERT INTO FAQ (\"Id\",\"category\", \"question\", \"answer\", \"sequence\", \"UserId\", \"created\") VALUES ('"+IdParam+"','"+categoryParam+"','"+questionParam+"','"+answerParam+"', '"+sequence+"', '"+ session.getAttribute("theName")+"', '"+dateString+"')   ");
  10.   }
  11. ResultSet columns = statement.executeQuery("SELECT * FROM FAQ");
  12. while(columns.next()) {
  13.     String Id  = columns.getString("Id");
  14.     String category  = columns.getString("category");
  15.     String question  = columns.getString("question");    
  16.     String answer = columns.getString("answer");
  17.     String userId  = columns.getString("userId");    
  18.     String created = columns.getString("created");
  19.     Integer sequence = columns.getInt("sequence");
  20.  
The jsp falls over with error regarding sequence as It cant convert between String to Integer and Int to Integer.

I've been looking at examples, but obviously I arent declaring the sequence value as an Integer properly.

Any advice would be appreciated
Cheers Rob
Mar 13 '08 #1
Share this Question
Share on Google+
2 Replies


Dököll
Expert 100+
P: 2,364
You should probably use an Auto-Generated ID in your back-end, if which case you would not need :
Expand|Select|Wrap|Line Numbers
  1.  
  2. String Id  = columns.getString("Id"); 
  3.  
  4.  
In which case, it should really be:

Expand|Select|Wrap|Line Numbers
  1.  
  2. int Id  = columns.getInt("Id"); 
  3.  
  4.  
but again, only if necessary would you need to insert id values in code. maintain your back-end to accept an auto number when data are added, then you can retrieve using getInt...
Dec 13 '08 #2

Expert 10K+
P: 11,448
@robtyketto
Here are the valid type specifications for an input field:

HTML input type Attribute

As you can see there is no such thing as an 'int' type; also note that this has nothing to do with auto generated values; forget about that; that reply was totally incorrect.

kind regards,

Jos
Dec 13 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.