| | |
Type mismatch: cannot convert from int to ResultSet
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
Hey guys!~
the code below is generating this error message "Type mismatch: cannot convert from int to ResultSet" there is no integer types in the database i have made sure they are all strings. I tried making a JavaBean and then just calling it frmo the JSP but when compiling the Bean i got a similar error message suggesting that the ResultSet return value was an int has it got somethign to do with executeUpdate? is there another way to insert the info from the form to the SQL database?
anyhelp would do awesome as my J2EE tutors are stumped
Cheers!
[jsp]
<hr>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
String usertype = request.getParameter("usertype");
String email = request.getParameter("email");
String title = request.getParameter("title");
String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
String state = request.getParameter("state");
String post = request.getParameter("post");
String country = request.getParameter("country");
String dob = request.getParameter("dob");
String credit = request.getParameter("credit");
String expiry = request.getParameter("expiry");
String login_date = request.getParameter("login_date");
%>
<%@ page import= "java.sql.*"%>
<%@ page import= "java.util.*"%>
<%@ page import= "java.lang.Integer"%>
<%@ page import= "javax.servlet.*"%>
<%@ page import= "javax.servlet.http.*"%>
<%@ page import= "java.io.*"%>
<%@ page import= "com.DBConnection"%>
<jsp:useBean id="dbbean" scope="application" class="com.DBConnection"/>
<html>
<head>
<title>Surf @ La Trobe - Registration Sign up</title>
</head>
<body bgcolor = "white" >
<%
%>
<h1> Registration !!!!! </h1>
<FORM ACTION= "play.jsp" METHOD= "POST">
<table width="302" height="462">
<tr>
<td height="54" width="79"> Username: </td>
<td height="54" width="211">
<input type= 'TEXT' name='username' size='30'>
</td>
</tr>
<tr>
<td height="45" width="79">Password:</td>
<td height="45" width="211">
<input type='PASSWORD' name='password'size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Verify Password:</td>
<td height="46" width="211">
<input type= 'PASSWORD' name='Verify Password' size='20'>
</td>
</tr>
<tr>
<td height="51" width="79">Type Of Member:</td>
<td height="51" width="211">
<input type= 'TEXT' name='usertype' size='20'>
</td>
</tr>
<tr>
<td height="51" width="79">Title:</td>
<td height="51" width="211">
<input type= 'TEXT' name='title' size='20'>
</td>
</tr>
<tr>
<td height="51" width="79">Name:</td>
<td height="51" width="211">
<input type= 'TEXT' name='firstname' size='20'>
</td>
</tr>
<tr>
<td height="51" width="79">Name:</td>
<td height="51" width="211">
<input type= 'TEXT' name='lastname' size='20'>
</td>
</tr>
<tr>
<td height="44" width="79">Phone:</td>
<td height="44" width="211">
<input type= 'TEXT' name='phone' size='20'>
</td>
</tr>
<tr>
<td height="94" width="79">Address: </td>
<td height="94" width="211">
<textarea name="address" cols="20" rows="3"></textarea>
</td>
</tr>
<tr>
<td height="46" width="79">email:</td>
<td height="46" width="211">
<input type= 'TEXT' name='email' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">State:</td>
<td height="46" width="211">
<input type= 'TEXT' name='state' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Post Code</td>
<td height="46" width="211">
<input type= 'TEXT' name='post' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Country</td>
<td height="46" width="211">
<input type= 'TEXT' name='country' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Date Of Birth:</td>
<td height="46" width="211">
<input type= 'TEXT' name='dob' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Credit Card:</td>
<td height="46" width="211">
<input type= 'TEXT' name='credit' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Expiry Date:</td>
<td height="46" width="211">
<input type= 'TEXT' name='expiry' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Login Date:</td>
<td height="46" width="211">
<input type= 'TEXT' name='login_date' size='20'>
</td>
</tr>
<tr>
<td height="25" width="79"></td>
<td height="25" width="211">
<input type='SUBMIT' size='10' value='SUBMIT' name="SUBMIT">
</td>
</tr>
<%
if(request.getMethod().equals("POST"))
{
DBConnection db = new DBConnection();
Connection con = db.getConnection();
%>
<h1> test?</h1>
<%
Statement statement = con.createStatement();
ResultSet rs = statement.executeUpdate(" INSERT INTO USERS VALUES( '"+username+"','"
+password+"','"+ usertype +"','"+ email +"','"+ title +"','"+ firstname +"','"+ lastname +"','"
+ phone +"','"+ address +"','"+ state +"','"+ post +"','"+ country +"','"+ dob +"','"+ credit +"','"
+ expiry +"','"+ login_date+"'");
}
else
{
out.println("<h1>something went wrong</h1>");
}
%>
</table>
</form>
</body>
</html>
[/jsp]
the code below is generating this error message "Type mismatch: cannot convert from int to ResultSet" there is no integer types in the database i have made sure they are all strings. I tried making a JavaBean and then just calling it frmo the JSP but when compiling the Bean i got a similar error message suggesting that the ResultSet return value was an int has it got somethign to do with executeUpdate? is there another way to insert the info from the form to the SQL database?
anyhelp would do awesome as my J2EE tutors are stumped

Cheers!
[jsp]
<hr>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
String usertype = request.getParameter("usertype");
String email = request.getParameter("email");
String title = request.getParameter("title");
String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
String state = request.getParameter("state");
String post = request.getParameter("post");
String country = request.getParameter("country");
String dob = request.getParameter("dob");
String credit = request.getParameter("credit");
String expiry = request.getParameter("expiry");
String login_date = request.getParameter("login_date");
%>
<%@ page import= "java.sql.*"%>
<%@ page import= "java.util.*"%>
<%@ page import= "java.lang.Integer"%>
<%@ page import= "javax.servlet.*"%>
<%@ page import= "javax.servlet.http.*"%>
<%@ page import= "java.io.*"%>
<%@ page import= "com.DBConnection"%>
<jsp:useBean id="dbbean" scope="application" class="com.DBConnection"/>
<html>
<head>
<title>Surf @ La Trobe - Registration Sign up</title>
</head>
<body bgcolor = "white" >
<%
%>
<h1> Registration !!!!! </h1>
<FORM ACTION= "play.jsp" METHOD= "POST">
<table width="302" height="462">
<tr>
<td height="54" width="79"> Username: </td>
<td height="54" width="211">
<input type= 'TEXT' name='username' size='30'>
</td>
</tr>
<tr>
<td height="45" width="79">Password:</td>
<td height="45" width="211">
<input type='PASSWORD' name='password'size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Verify Password:</td>
<td height="46" width="211">
<input type= 'PASSWORD' name='Verify Password' size='20'>
</td>
</tr>
<tr>
<td height="51" width="79">Type Of Member:</td>
<td height="51" width="211">
<input type= 'TEXT' name='usertype' size='20'>
</td>
</tr>
<tr>
<td height="51" width="79">Title:</td>
<td height="51" width="211">
<input type= 'TEXT' name='title' size='20'>
</td>
</tr>
<tr>
<td height="51" width="79">Name:</td>
<td height="51" width="211">
<input type= 'TEXT' name='firstname' size='20'>
</td>
</tr>
<tr>
<td height="51" width="79">Name:</td>
<td height="51" width="211">
<input type= 'TEXT' name='lastname' size='20'>
</td>
</tr>
<tr>
<td height="44" width="79">Phone:</td>
<td height="44" width="211">
<input type= 'TEXT' name='phone' size='20'>
</td>
</tr>
<tr>
<td height="94" width="79">Address: </td>
<td height="94" width="211">
<textarea name="address" cols="20" rows="3"></textarea>
</td>
</tr>
<tr>
<td height="46" width="79">email:</td>
<td height="46" width="211">
<input type= 'TEXT' name='email' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">State:</td>
<td height="46" width="211">
<input type= 'TEXT' name='state' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Post Code</td>
<td height="46" width="211">
<input type= 'TEXT' name='post' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Country</td>
<td height="46" width="211">
<input type= 'TEXT' name='country' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Date Of Birth:</td>
<td height="46" width="211">
<input type= 'TEXT' name='dob' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Credit Card:</td>
<td height="46" width="211">
<input type= 'TEXT' name='credit' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Expiry Date:</td>
<td height="46" width="211">
<input type= 'TEXT' name='expiry' size='20'>
</td>
</tr>
<tr>
<td height="46" width="79">Login Date:</td>
<td height="46" width="211">
<input type= 'TEXT' name='login_date' size='20'>
</td>
</tr>
<tr>
<td height="25" width="79"></td>
<td height="25" width="211">
<input type='SUBMIT' size='10' value='SUBMIT' name="SUBMIT">
</td>
</tr>
<%
if(request.getMethod().equals("POST"))
{
DBConnection db = new DBConnection();
Connection con = db.getConnection();
%>
<h1> test?</h1>
<%
Statement statement = con.createStatement();
ResultSet rs = statement.executeUpdate(" INSERT INTO USERS VALUES( '"+username+"','"
+password+"','"+ usertype +"','"+ email +"','"+ title +"','"+ firstname +"','"+ lastname +"','"
+ phone +"','"+ address +"','"+ state +"','"+ post +"','"+ country +"','"+ dob +"','"+ credit +"','"
+ expiry +"','"+ login_date+"'");
}
else
{
out.println("<h1>something went wrong</h1>");
}
%>
</table>
</form>
</body>
</html>
[/jsp]
executeUpdate returns an int indicating how many rows were affected by the query. It does not return a resultset. So, on the line where you are carrying out an executeUpdate, you should not be expecting a ResultSet as the return value.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
executeUpdate returns an int indicating how many rows were affected by the query. It does not return a resultset. So, on the line where you are carrying out an executeUpdate, you should not be expecting a ResultSet as the return value.
[jsp]
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = statement.executeQuery(" SELECT * FROM USERS");
rs.moveToInsertRow();
rs.updateString(1, username);
rs.updateString(2, password);
rs.updateString(3, usertype);
rs.updateString(4, email );
rs.updateString(5, title);
rs.updateString(6, firstname);
rs.updateString(7, lastname);
rs.updateString(8, phone);
rs.updateString(9, address);
rs.updateString(10, state);
rs.updateString(11, post);
rs.updateString(12, country);
rs.updateString(13, dob);
rs.updateString(14, credit);
rs.updateString(15, expiry);
rs.updateString(16, login_date);
rs.insertRow();
[/jsp]
and now it works beautifully! thanks for you help!
cheers.
And, yes it would have helped. Using an Updateable ResultSet was not the fix. There is no need to evaluate what is returned from an executeUpdate. Using an updateable resultset in this situation is complete overkill. Removing the return help would have fixed the problem posted. Any additional error was probably in the formulation of your query. Had you made the change requested, then posted again with the next error, we would have helped you get your query right. Which probably would have entailed telling you to use a PreparedStatement which would be used almost exactly like an updateable resultset without having to fetch anything from the database. You will probably, as time goes on, find out that this portion of your application gets slower, and slower, and slower, since in order to update the record you are trying to update, you must first fetch all users out of the database which will use up time and resources (and as you get more users these things will not be trivial) that you don't need to use.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
Oh i see, yeah thats a much better idea. I get what you mean by it gradually using up more an more time as the DB gets bigger and bigger, since its doing a select all first. The PreparedStatement works a treat. I am now trying to make it generate some kind of error unless all fields are entered this is what i have added
[jsp]
if(username == "" || password == ""|| usertype == ""|| email == ""|| title== ""|| firstname== ""
|| lastname== ""|| phone== ""|| address== ""|| state== ""|| post== ""|| country== ""|| dob== ""
|| credit== ""|| expiry== ""|| login_date== "")
{
out.println("<h1>Please enter all mandatory fields</h1>");
}
else
{
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = statement.executeQuery(" SELECT * FROM USERS");
rs.moveToInsertRow();
rs.updateString(1, username);
rs.updateString(2, password);
rs.updateString(3, usertype);
rs.updateString(4, email );
rs.updateString(5, title);
rs.updateString(6, firstname);
rs.updateString(7, lastname);
rs.updateString(8, phone);
rs.updateString(9, address);
rs.updateString(10, state);
rs.updateString(11, post);
rs.updateString(12, country);
rs.updateString(13, dob);
rs.updateString(14, credit);
rs.updateString(15, expiry);
rs.updateString(16, login_date);
rs.insertRow();
}
}
[/jsp]
Though this seems to do absolutely nothing, it always has "please enter all fields" at the bottom of the form. Im sure im going about this all wrong, could you possilbly point me in the right direction?
Thanks a bundle.
[jsp]
if(username == "" || password == ""|| usertype == ""|| email == ""|| title== ""|| firstname== ""
|| lastname== ""|| phone== ""|| address== ""|| state== ""|| post== ""|| country== ""|| dob== ""
|| credit== ""|| expiry== ""|| login_date== "")
{
out.println("<h1>Please enter all mandatory fields</h1>");
}
else
{
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = statement.executeQuery(" SELECT * FROM USERS");
rs.moveToInsertRow();
rs.updateString(1, username);
rs.updateString(2, password);
rs.updateString(3, usertype);
rs.updateString(4, email );
rs.updateString(5, title);
rs.updateString(6, firstname);
rs.updateString(7, lastname);
rs.updateString(8, phone);
rs.updateString(9, address);
rs.updateString(10, state);
rs.updateString(11, post);
rs.updateString(12, country);
rs.updateString(13, dob);
rs.updateString(14, credit);
rs.updateString(15, expiry);
rs.updateString(16, login_date);
rs.insertRow();
}
}
[/jsp]
Though this seems to do absolutely nothing, it always has "please enter all fields" at the bottom of the form. Im sure im going about this all wrong, could you possilbly point me in the right direction?
Thanks a bundle.
You can't, generally, compare strings with == you should do it as follows:
or
Since getParameter can return a null value, and I don't believe that
will return true if username is null, a check for the null string is needed as well as the check for a nonempty value.
JSP Syntax (Toggle Plain Text)
if ((usermame == null) || (username.length() == 0)) { }
JSP Syntax (Toggle Plain Text)
if ((usermame == null) || (username.equals(""))) { }
Since getParameter can return a null value, and I don't believe that
JSP Syntax (Toggle Plain Text)
"".equals(username)
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
javascript for validation and not null would be fine, except for those people that disable javascript in their browsers, and them doing that should not affect the ability of your jsp to deal with their input and in this case it would as a nullpointer exception would be thrown.
JavaScript is nice to use. You can accomplish a lot with it, but you should never depend on client side verification.
JavaScript is nice to use. You can accomplish a lot with it, but you should never depend on client side verification.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Type mismatch (ASP)
- Type Mismatch Error (MS SQL)
- Adding the results of two text boxes (Visual Basic Express Edition) (VB.NET)
- error C2664: cannot convert parameter 1 from 'float **__w64 ' to 'float *' (C)
- how to sort out type mismatch error while retreiving attribute from LDAP (Visual Basic 4 / 5 / 6)
Other Threads in the JSP Forum
- Previous Thread: Please help(Problem in insertion data to database)
- Next Thread: Problem with jsp include directive in iPlanet. Working in Tomcat.
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






