473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Java Integer question involving JSP/HTML FORM

108 100+
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
2 3850
Dököll
2,364 Expert 2GB
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
JosAH
11,448 Expert 8TB
@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

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

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
17
by: Robert Baer | last post by:
I used Google and found some references for integer in Java. But "int" not only does not work, it also prevents reading X and Y coordinates of the mouse. What i would like to do: 1) Get X and Y...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interfaceâ€. In a functional language, a function can be specified by its name and parameter specs....
7
by: judge82 | last post by:
please I am learning how to use servlet. here is my code package TestWebApp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class...
1
by: gypsyman58 | last post by:
First I need to create 2 classes. The first will contain an ID number and an array of 5 course titles. I also have to create a get and a set method for populating the ID. I also must create a method...
49
by: aarklon | last post by:
Hi all, See:- http://www.cs.princeton.edu/introcs/faq/c2java.html for C vs Java in number crunching http://husnusensoy.blogspot.com/2006/06/c-vs-java-in-number-crunching.html
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.