RSS Forums RSS
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 15162 | Replies: 4
Reply
Join Date: Sep 2005
Posts: 139
Reputation: aarya is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
aarya's Avatar
aarya aarya is offline Offline
Junior Poster

insert values to mysql database

  #1  
May 31st, 2006
hi

i am trying to insert into mysql databse using jsp.but i am getting the error as


An error occured between lines: 38 and 47 in the jsp file: /jsp/havyaka/register.jsp

Generated servlet error:
C:\tomcat\work\localhost\examples\jsp\havyaka\register$jsp.java:102: Incompatible type for declaration. Can't convert int to java.sql.ResultSet.
                ResultSet rs = statement.executeUpdate("insert into havyak(usercode,password,email,name,phone,add1,add2,add3,add4,country) values('" + usercode + "','" + password + "','" + email + "','" + name + "','" + phone + "','" + add1 + "','" + add2 + "','" + add3 + "','" + add4 + "','" + country + "')");
^


my code is

<%
String usercode=request.getParameter("usercode");
session.setAttribute( "theuser", usercode );

String password =request.getParameter("password");
session.setAttribute( "thepass", password );

String email=request.getParameter("email");
session.setAttribute( "theemail", email );

String name=request.getParameter("name");
session.setAttribute( "thename", name );

String phone=request.getParameter("phone");
session.setAttribute( "thephone", phone );

String add1=request.getParameter("address1");


String add2=request.getParameter("address2");
String add3=request.getParameter("address3");
String add4=request.getParameter("address4");
String country=request.getParameter("country");

%>




<%@ page import="java.sql.*" %>
<%
String connectionURL = "jdbc:mysql://localhost/login?user=user ;password=pass";

%>

<html><body>

<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(connectionURL, "", "");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeUpdate("insert into havyak(usercode,password,email,name,phone,add1,add2,add3,add4,country) values('" + usercode + "','" + password + "','" +

email + "','" + name + "','" + phone + "','" + add1 + "','" + add2 + "','" + add3 + "','" + add4 + "','" + country + "')");




%>
submitted
</body></html>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,559
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 11
Solved Threads: 144
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: insert values to mysql database

  #2  
Jun 2nd, 2006
executeUpdate returns an int indicating the number of rows affected
by the query. It does not return a ResultSet.
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
Reply With Quote  
Join Date: Sep 2005
Posts: 139
Reputation: aarya is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
aarya's Avatar
aarya aarya is offline Offline
Junior Poster

Re: insert values to mysql database

  #3  
Jun 2nd, 2006
Originally Posted by masijade
executeUpdate returns an int indicating the number of rows affected
by the query. It does not return a ResultSet.


yes with that warning i guessed then how i ahve to insert into the database
Reply With Quote  
Join Date: Feb 2006
Posts: 1,559
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 11
Solved Threads: 144
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: insert values to mysql database

  #4  
Jun 6th, 2006
By doing exactly what ypu are doing, but storing the result of the
executeUpdate in an int rather than a ResultSet. You can then check
that the integer is not 0 if you want to make sure that something was
inserted. After you have made this change, try your program again.
If nothing is being inserted, you will at least, probably get a better
error message than the one you are getting now. This error message
is being thrown during compileation. Up to this point, nothing has been
executed.
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
Reply With Quote  
Join Date: Oct 2006
Posts: 1
Reputation: Harika.it is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Harika.it Harika.it is offline Offline
Newbie Poster

Re: insert values to mysql database

  #5  
Oct 24th, 2006
Originally Posted by aarya View Post
hi

i am trying to insert into mysql databse using jsp.but i am getting the error as


An error occured between lines: 38 and 47 in the jsp file: /jsp/havyaka/register.jsp

Generated servlet error:
C:\tomcat\work\localhost\examples\jsp\havyaka\register$jsp.java:102: Incompatible type for declaration. Can't convert int to java.sql.ResultSet.
                ResultSet rs = statement.executeUpdate("insert into havyak(usercode,password,email,name,phone,add1,add2,add3,add4,country) values('" + usercode + "','" + password + "','" + email + "','" + name + "','" + phone + "','" + add1 + "','" + add2 + "','" + add3 + "','" + add4 + "','" + country + "')");
^


my code is

<%
String usercode=request.getParameter("usercode");
session.setAttribute( "theuser", usercode );

String password =request.getParameter("password");
session.setAttribute( "thepass", password );

String email=request.getParameter("email");
session.setAttribute( "theemail", email );

String name=request.getParameter("name");
session.setAttribute( "thename", name );

String phone=request.getParameter("phone");
session.setAttribute( "thephone", phone );

String add1=request.getParameter("address1");


String add2=request.getParameter("address2");
String add3=request.getParameter("address3");
String add4=request.getParameter("address4");
String country=request.getParameter("country");

%>




<%@ page import="java.sql.*" %>
<%
String connectionURL = "jdbc:mysql://localhost/login?user=user ;password=pass";

%>

<html><body>

<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(connectionURL, "", "");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeUpdate("insert into havyak(usercode,password,email,name,phone,add1,add2,add3,add4,country) values('" + usercode + "','" + password + "','" +

email + "','" + name + "','" + phone + "','" + add1 + "','" + add2 + "','" + add3 + "','" + add4 + "','" + country + "')");




%>
submitted
</body></html>




hi

This is Harika. Now i got the same task to do. Would u now help me about this.
I have to write a jsp file which reads the values from html file having textfields and those has to b inserted in to database mysql through the driver com.mysql.jdbc.Drive. Would you show me jsp file regarding to this.

Thank you.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:10 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC