0
CREATE TABLE IF NOT EXISTS tmp_park_log (
  uniqueid VARCHAR (20),
  parked_sec INT
) ;
DELETE 
FROM
  tmp_park_log ;
INSERT INTO tmp_park_log (uniqueid, parked_sec) 
SELECT 
  uniqueid,
  SUM(parked_sec) 
FROM
  park_log 
GROUP BY uniqueid ;

This is executing successfully in MySql: But, when i put this in a string and use Prepared Statement it gives following Error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELETE FROM tmp_park_log;  INSERT INTO tmp_park_log (uniqueid, parked_sec) SELEC' at line 1
1
  • You should put each command into separate statement. Commented Jan 6, 2014 at 7:22

3 Answers 3

1

SQL syntax for prepared statements does not support multi-statements (that is, multiple statements within a single string separated by “;” characters).

See here: http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html

Sign up to request clarification or add additional context in comments.

Comments

0

In the first case you arent using one commando instead you use a few commandos and when you put it in a string as a prepared statement you must create one prepared statement for every single commando you want to execute.

Comments

0

Since you didn't attached the Java code I assume you are trying to d prepare statement for all the text and not to prepare every and execute it.

few hints:

  1. There is no need to prepare the CREATE TABLE statement you can just use create statement and execute it (as no bind variables are used) http://docs.oracle.com/javase/tutorial/jdbc/basics/tables.html
  2. If your application allows it , consider the use of truncate instead of delete, it will be faster and reduce the log generation.
  3. Don't forget to commit :).

BR

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.