在进行写入数据库时,objec变量赋值时的顺序应该和数据库value的数据一一对应,否则格式错误
String sql = "insert into topic(c_id, title, content, pv, user_id, username, user_img, create_time, update_time, hot, deleted) values(?,?,?,?,?,?,?,?,?,?,?)" ;
//objec里面的数据顺序应该和数据库value顺序一致。data in object should has the same order with the date in values, if not, we get an error which about the variable types
Object [] params = {
topic.getcId(),
topic.getTitle(),
topic.getContent(),
topic.getPv(),
topic.getUserId(),
topic.getUsername(),
topic.getUserImg(),
topic.getCreateTime(),
topic.getUpdateTime(),
topic.getHot(),
topic.getDeleted()
};
在数据库编程中,进行插入操作时,对象变量的赋值顺序必须与SQL语句中的占位符顺序保持一致。例如,在一个示例中,一个话题对象的属性按特定顺序赋值到SQL的问号参数中,以确保数据类型匹配,避免格式错误。这个过程对于正确保存和更新数据至关重要。
8672

被折叠的 条评论
为什么被折叠?



