我是jsp的新手。我试图通过jsp页面将数据插入表中。我的代码运行正常,所有值都正确传递给语句。但是,在最后一个值之后,它应该移动到executeUpdate命令,但它转移到返回命令,而返回0并且数据不会插入到数据库中。我的代码在这里。
RegisterDao.java
package RegBean;
import java.sql.*;
/**
*
* @author syedahmed
*/
public class RegisterDao {
public static int register(user u){
int status = 0;
try{
Connection con = ConnectionProvider.getCon();
PreparedStatement ps = con.prepareStatement("insert into register(uname,ulogin,upass,Gender,ucontact,Email) values(?,?,?,?,'',?)");
ps.setString(1,u.getUname());
ps.setString(2,u.getUlogin());
ps.setString(3,u.getUpass());
ps.setString(4,u.getGender());
ps.setString(5,u.getUcontact());
ps.setString(6,u.getEmail());
status=ps.executeUpdate();
}catch(Exception e){}
return status;
}
}
process.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "RegBean.RegisterDao"%>
<jsp:useBean id="obj" class="RegBean.user"/>
<jsp:setProperty property="*" name="obj"/>
<%
int status = RegisterDao.register(obj);
if(status>0)
out.print("You are successfully Logged in");
else
out.print("unsuccessful");
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
的index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<form action="process.jsp">
<input type="text" name="uname" value="Name..." onclick="this.value=''"/><br/>
<input type="text" name="ulogin" value="Login ID..." onclick="this.value=''"/><br/>
<input type="password" name="upass" value="Password..." onclick="this.value=''"/><br/>
<input type="radio" name="gender" value="Male"> Male<br>
<input type="radio" name="gender" value="Female"> Female<br>
<input type="radio" name="gender" value="Other"> Other<br>
<input type="text" name="ucontact" value="Contact#..." onclick="this.value=''"/><br/>
<input type="email" name="email" value="email..." onclick="this.value= ''"/><br/>
<input type="submit" value="register"/>
</form>
</html>
&#13;
答案 0 :(得分:0)
这意味着你在try部分执行的代码失败了。在catch部分显示stacktrace以查看错误。
try{
...
}catch(Exception e){
e.printStackTrace()
}
答案 1 :(得分:0)
问题已经解决..查询中有错误..
"insert into register(uname,ulogin,upass,Gender,ucontact,Email) values(?,?,?,?,'',?)" ..