title: Query runs in MySql workbench but not in Java eclipse
body: <p>I have created a query that is working properly in MySQL workbench but when i run it in eclipse is not working. Connection with database is working properly because with simpler queries I had correct results.</p>
  
  <p>java code:</p>
  
  <pre><code>                String queryAlter = "SELECT count(*) ";
                  queryAlter += "INTO @exist ";
                  queryAlter += "FROM information_schema.columns ";
                  queryAlter += "WHERE table_schema = database() ";
                  queryAlter += "and COLUMN_NAME = 'question" + (100 + number + 1)+"' ";
                  queryAlter += "AND table_name = '"+ tableName+"'; ";
  
                  queryAlter += "set @query = IF(@exist &lt;= 0, 'alter table "+ tableName+" add column question" + (100 + number + 1)+" varchar(2048) NULL', ";
                  queryAlter += "'select \\'Column Exists\\' status'); ";
                  queryAlter += "use joomla30; ";
                  queryAlter += "prepare stmt from @query; ";
  
                  queryAlter += "EXECUTE stmt;";
  </code></pre>
  
  <p>and I get this message:</p>
  
  <p>An error occurred. Maybe user/password is invalid
  com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'set @query = IF(@exist &lt;= 0, 'alter table n0x3c_twoquestions_table add column qu' at line 1</p>
  
  <p>also the string of query is: </p>
  
  <pre><code> SELECT count(*) INTO @exist FROM information_schema.columns WHERE table_schema = database() and COLUMN_NAME = 'question101' AND table_name = 'n0x3c_twoquestions_table'; set @query = IF(@exist &lt;= 0, 'alter table n0x3c_twoquestions_table add column question101 varchar(2048) NULL', 'select \'Column Exists\' status'); use joomla30; prepare stmt from @query; EXECUTE stmt;
  </code></pre>
  
  <p>I also tried this in java that I have read from <a href="https://stackoverflow.com/questions/21936864/mysql-query-works-in-phpmyadmin-but-not-in-java-eclipse">MySQL Query works in PhpMyAdmin but not in JAVA Eclipse</a> : </p>
  
  <pre><code>                String s1 = "SELECT count(*) INTO @exist FROM information_schema.columns WHERE table_schema = database() and COLUMN_NAME = 'question" + (100 + number + 1)+"' AND table_name = '"+ tableName+"'; ";
  
                  String s2 = "set @query = IF(@exist &lt;= 0, 'alter table "+ tableName+" add column question" + (100 + number + 1)+" varchar(2048) NULL', 'select \\'Column Exists\\' status'); ";
                  String s3 = "use joomla30; ";
                  String s4 = "prepare stmt from @query; ";
  
                  stmt.addBatch(s1);
                  stmt.addBatch(s2);    
                  stmt.addBatch(s3);   
                  stmt.addBatch(s4);
  
                  stmt.executeBatch();
                  conn1.commit();
  </code></pre>
  
  <p>but I have this error:</p>
  
  <p>java.sql.BatchUpdateException: Can not issue SELECT via executeUpdate().</p>