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 :D

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.

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.

Hahah yeah i found that answer on another post but it didnt really help jsut cos im a java noob and couldnt think of any other way to fix the problem. Though for all of you who have a similar error i fixed it by doing this
[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.

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.

You can't, generally, compare strings with == you should do it as follows:

if ((usermame == null) || (username.length() == 0)) {
}

or

if ((usermame == null) || (username.equals(""))) {
}

Since getParameter can return a null value, and I don't believe that

"".equals(username)

will return true if username is null, a check for the null string is needed as well as the check for a nonempty value.

i have a suggestion a shorter line for the null hope it helps

Code:
if (username.length() <= -1) {
}

i suggest you create a javascript for validation. so that required fields all have a value. and to make sure that they are not null ^_^

Ken - Ken

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.

how to solved the error Type mismatch: cannot convert from Set<NeighbourConfiguration> to NeighbourConfiguration

NeighbourConfiguration NeighbourConfiguration = EnodeBConfigurationMgmt.getNeighbourConfiguration(nibEnbConfigId);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.