INSERT出的问题,谢谢
来源: 互联网 发布时间:2015-09-08
本文导语: 下面是JAVABEAN中的一个方法,在JSP中使用它时提示INSERT出错,是什么原因呢?SELECT时都是好的。 public void r_insertUser(String username, String password ) throws SQLException, Exception { if (con != null) { try{ // c...
下面是JAVABEAN中的一个方法,在JSP中使用它时提示INSERT出错,是什么原因呢?SELECT时都是好的。
public void r_insertUser(String username, String password ) throws SQLException, Exception
{
if (con != null)
{
try{
// create a prepared SQL statement
ResultSet rs=null;
PreparedStatement insertuser;
insertuser = con.prepareStatement("INSERT INTO user VALUS(?,?);");
insertuser.setString(1, username);
insertuser.setString(2, password);
insertuser.execute();
}
catch (SQLException sqle)
{
error = "Exception: insert error .";
throw new Exception(error);
}
}
else
{
error = "Exception: Connection to database was lost.";
throw new Exception(error);
}
} // end of login checkUser()
user表的结构是字符串的username,password.没有设置主键
public void r_insertUser(String username, String password ) throws SQLException, Exception
{
if (con != null)
{
try{
// create a prepared SQL statement
ResultSet rs=null;
PreparedStatement insertuser;
insertuser = con.prepareStatement("INSERT INTO user VALUS(?,?);");
insertuser.setString(1, username);
insertuser.setString(2, password);
insertuser.execute();
}
catch (SQLException sqle)
{
error = "Exception: insert error .";
throw new Exception(error);
}
}
else
{
error = "Exception: Connection to database was lost.";
throw new Exception(error);
}
} // end of login checkUser()
user表的结构是字符串的username,password.没有设置主键
|
insertuser = con.prepareStatement("INSERT INTO user VALUS(?,?);");
VALUS 拼错了
VALUS 拼错了