954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

insert values to mysql database

<%
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

aarya
Junior Poster
139 posts since Sep 2005
Reputation Points: 11
Solved Threads: 0
 

executeUpdate returns an int indicating the number of rows affected
by the query. It does not return a ResultSet.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 
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

aarya
Junior Poster
139 posts since Sep 2005
Reputation Points: 11
Solved Threads: 0
 

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.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

<%
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

Harika.it
Newbie Poster
1 post since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

it works like this as u want to insert values into the table...

u need to put this where you want your insert code

// at first u need to get your form data into the jsp variables using the getParameter function"


// // this table is for printing data in table which im doing below

<%

try
{
String my_sql_statement = "insert into [tablename] (fieldname1,fieldname2,fieldname3) values ('" + value1 + "','" + value2 "',"' + value3 "')";

Class.foName("com.mysql.jdbc.Driver").newInstance;
Connection con = DriverManager.getConnection;

Statement s1 = con.createStatement();
int value = executeUpdate(my_sql_statement);

//and now if you want to check that you have inserted them properly

String my_sql_statement2 = "select * from [tablename]";

ResultSet rs=s1.executeQuery(my_sql_statement2);

while(rs.next())
{
//now get the values of those jsp table in a string like suppose u have only 1 column //in ur table so it would be like this and column name is username

String my_username = rs.getString("username");
//and if you want to disply it 

%> <tr><td><%= my_username %> </td></tr>

<%
} // end while

} // end try
%>
</table>

<%

catch (Exception e )
{
out.print(e);
}
finally
{
}
%>

minor errors may be there but this will be the logic

gauravleoheart
Newbie Poster
1 post since Feb 2010
Reputation Points: 8
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You