title: JDBC Connection error while executing a procedure from java
body: <p>I have to execute a stored procedure from a java class by passing value. But when I am trying for that, I am getting the error </p>
  
  <pre><code>Exception in thread "main" 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 'NULL' at line 1
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
      at com.mysql.jdbc.Util.getInstance(Util.java:381)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
      at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:995)
      at com.coolminds.action.OperatorBillCorrection.main(OperatorBillCorrection.java:27)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  </code></pre>
  
  <p>here is my code.</p>
  
  <pre><code>public class OperatorBillCorrection {
  
      public static void main(String args[]) throws SQLException {
          try {
              Class.forName("com.mysql.jdbc.Driver");
              Connection con=DriverManager.getConnection(
                      "jdbc:mysql://localhost:3306/webill_operator_2016","root","root123");
              String opCode="KL04C019" ;
  
              for(int i=0;i&lt;=12;i++)  {
                  String dt=  "2015-"+i+"-1" ;
                  PreparedStatement stmts=con.prepareStatement("call sp_getOperatorCollection(?,?)") ;
                  stmts.setString(1,opCode);
                  stmts.setString(2,dt);
                  stmts.execute();
  
              }
              for(int i=0;i&lt;=2;i++)    {
                  String dt=  "2016-"+i+"-1" ;
                  PreparedStatement stmts=con.prepareStatement("call sp_getOperatorCollection(?,?)") ;
                  stmts.setString(1,opCode);
                  stmts.setString(2,dt);
                  stmts.execute();
              }
  
              System.out.println("Completed")  ;
              con.close();
          } catch (ClassNotFoundException e) {
              e.printStackTrace();  
          }
      }
  }
  </code></pre>
  
  <p>It is working when I am using Statement <code>stmt=con.createStatement(); stmt.execute("call sp_getOperatorCollection('KL04C019','2015-09-01')");</code> Instead of PreparedStatement</p>