PreparedStatement pstmt;
for (int i = 0; i < cnt; i++) {
String squery = "insert into response(seat_no,question_no,ans_opt,screenshot) values(?,?,?,?)";
pstmt = con.prepareStatement(squery);
pstmt.setString(1, cd.getseat());// This is for fetching seat number
pstmt.setInt(2, i + 1);// This is for question number
pstmt.setString(3, res[i].getAns());//This is for rensponse answer
pstmt.setBytes(4, res[i].getScshot());// This is for screenshot byte array
int num = pstmt.executeUpdate(squery);
Toast.makeText(getApplicationContext(), String.valueOf(num), Toast.LENGTH_SHORT).show();
}
My Table in Sql server 2008 R2
Response Table
seat_no nVARCHAR(MAX);
question_no int;
ans_opt text;
screenshot image;
It says error when inserting like "Use of the executeUpdate(String) method is not supported on this type of statement"
You've already specified the SQL when you prepared the statement:
pstmt = con.prepareStatement(squery);
You shouldn't then use Statement.executeUpdate(String)
- instead, just use the parameterless executeUpdate()
method:
int num = pstmt.executeUpdate();
You might also want to consider reusing the same PreparedStatement
for several calls, or using addBatch
to execute multiple updates in one go.
See more on this question at Stackoverflow