up 所有楼上 int java.sql.PreparedStatement.executeUpdate() throws SQLException Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement. Returns: either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing Throws: SQLException if a database access error occurs; this method is called on a closed PreparedStatement or the SQL statement returns a ResultSet object
PreparedStatement s = null;
Connection con = null;
try {
con = DatabaseUtil.getConnection();
con.setAutoCommit(false);
s = con.prepareStatement(INSERT_STRING);
String seq = this.getSequenceString();
s.setString(1, seq);
s.setString(3, aaa.getTitle());
s.setString(4, aaa.getRssUrl());
int i = s.executeUpdate();
con.commit();
return i;然后判断i为0则不成功,大于0则成功。
如:
int count = pstm.executeUpdate();
count 为影响的行数
if(count>0){
//执行成功 跳到 success.jsp
}else{
//执行失败 跳到 faise.jsp
}
从数据库中查询下你的数据。
在执行数据库操作的函数将结果返回给页面.
如:
int count = pstm.executeUpdate();
count 为影响的行数
if(count>0){
//执行成功 跳到 success.jsp
}else{
//执行失败 跳到 faise.jsp
}
难道楼主在JSP页面里直接插入?
Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement. Returns:
either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
Throws:
SQLException if a database access error occurs; this method is called on a closed PreparedStatement or the SQL statement returns a ResultSet object
try
{
插入数据库
跳转到success.jsp.
}
catch(Exception e)
{
rollback...
跳转到failed.jsp
}
fanally
{
close....
}
这句话的后面赋为真就行了,如果为真表示执行成功.
int i=pstm.executeUpdate();
if(i>0){
response.sendRedirect("success.jsp");
}else{
response.sendRedirect("faile.jsp");
}