考虑以下代码,
<div class="note" contenteditable="true"><span id='close' onclick='this.parentNode.parentNode.removeChild(this.parentNode)'>
<img src="http://lorempixel.com/40/40/abstract/1/" height="30" width="30" align="right" style="vertical-align: top; float: right"/>
</span>Type here</div>
问题是我的String query1 = "insert into quizquestion (ques, quizId) values "
+ "('"+ques+"', '"+quizId+"')";
s = con.createStatement();
s.executeUpdate(query1, Statement.RETURN_GENERATED_KEYS);
rs = s.getGeneratedKeys();
if (rs.next()){
quesId=rs.getString(1);
}
con.setAutoCommit(false);
String query2 = "insert into quizOption (option, quizQuesId, correct) values (?,?,?)";
ps = con.prepareStatement(query2);
for(int i=0; i<options.length; i++){
ps.setString(1, options[i]);
ps.setString(2, quesId);
if(correctOption.equals((i+1)+"")){
ps.setString(3, "1");
}else{
ps.setString(3, "0");
}
ps.addBatch();
}
int x[] = ps.executeBatch();
con.commit();
con.close();
return true;
已成功执行,但我获得了query1
我收到的一个示例错误如下,
query2
为什么我得到这个例外的任何想法? 提前谢谢。
答案 0 :(得分:1)
您的query2
包含MySQL reserved keyword,option
。这可能导致问题。尝试将列名括在引号(“)或反引号(`)中,如下所示:
String query2 = "insert into quizOption (\"option\", quizQuesId, correct) values (?,?,?)";