I'm working on Java and use Access (SQL) database. I want to insert into a table as you can see:
ResultSet resultSet = statement.executeQuery("INSERT INTO Mybooks (category,book_id) VALUES ('" + variable + "'," + 64) + ")");
However, a strange error comes:
Caused by: org.hsqldb.HsqlException: General error
Use executeUpdate
for database write operations
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO Mybooks (category,book_id) VALUES (?, ?)"); // no SQL injection here!
insertStatement.setString(1, variable);
insertStatement.setInt(2, 64);
insertStatement.executeUpdate();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.