try {
int c=1;
pstmt = conn.prepareStatement(NHMQueryConstant.INSERT_INTO_USER.toString());
pstmt.setInt(c++, userID);
pstmt.setInt(2, userTypeID);
pstmt.setString(c++,userName);
pstmt.setString(c++,NameInHindi);
pstmt.setString(c++,loginID);
pstmt.setString(c++,password);
int result = Integer.parseInt(mobile);
System.out.println(result);
pstmt.setInt(c++,result);
pstmt.setString(c++,email);
System.out.println(email);
/*
java.util.Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dob);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
pstmt.setDate(c++, sqlDate);
System.out.println(sqlDate);
*/
//pstmt.setDate(++c,new Date(new java.util.Date().getTime()));
pstmt.executeUpdate();
}
public static final String INSERT_INTO_USER = new StringBuilder("")
.append("INSERT INTO m_user_master (M_User_Id,User_Type_ID,M_User_Name,M__User_Name_Hindi,Login_ID,Password,Mobile,Email)")
.append("VALUES(USER_ID_SEQ.NEXTVAL,'2',?,?,?,?,?,?)").toString();
我收到错误User_ID_seq.nextval unknown column.how我可以插入获取参数索引超出范围。
答案 0 :(得分:0)
如果你有自动生成的ID(例如MySQL语法中的AUTOINCREMENT)并且不想关心id你可能会喜欢这个
public static final String INSERT_INTO_USER = "INSERT INTO " +
"m_user_master (M_User_Name,M__User_Name_Hindi,Login_ID,Password,Mobile,Email)" +
" VALUES('2',?,?,?,?,?,?)";
你必须删除
pstmt.setInt(c++, userID);
pstmt.setInt(2, userTypeID);
如果你想在Java中处理ID生成,那么你可以这样做
public static final String INSERT_INTO_USER = "INSERT INTO " +
"m_user_master (M_User_Id,M_User_Name,M__User_Name_Hindi,Login_ID,Password,Mobile,Email)" +
" VALUES(?,'2',?,?,?,?,?,?)";
并仅删除
pstmt.setInt(2, userTypeID);