How to pass null value in stored procedure from Java?
<p>I want to insert/update data to DB in my project. I have created a stored procedure in mysql. There are some input parameters i need to send from my java code. Sometimes the values of those parameters can be null(when user is not sending a value for that field). but I am not able to pass that null value from my java code to stored procedure.
My Code is :-</p>

<pre><code>    StoredProcedureQuery query = manager.createStoredProcedureQuery("updateProfile");
    query.registerStoredProcedureParameter("empName", String.class, ParameterMode.IN);
    query.registerStoredProcedureParameter("fatherName", String.class, ParameterMode.IN);
    query.setParameter("empId", model.getEmpName());
    query.setParameter("fatherName", model.getfatherName());
    query.execute();
</code></pre>

<p>Now, here I am getting only empName from user. So when i execute it I am getting error.</p>

<pre><code>Caused by: java.sql.SQLException: No value specified for parameter 2
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:695)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:663)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:653)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:638)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:606)
at com.mysql.cj.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2166)
at com.mysql.cj.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2146)
at com.mysql.cj.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2083)
at com.mysql.cj.jdbc.PreparedStatement.execute(PreparedStatement.java:1120)
at com.mysql.cj.jdbc.CallableStatement.execute(CallableStatement.java:790)
at org.hibernate.result.internal.OutputsImpl.&lt;init&gt;(OutputsImpl.java:51)
</code></pre>

<p>I have more than 20 fields which user can send and all are optional. SO i dont want add a if condition to check the value is null in my java code. So I want to know whether there is a way to pass the null value from java code to stored procedure.</p>