Problems set null jdbc


#1

I have problem that when write my insert in the MapD through JDBC, with some parameters NULL using

statement.setNull(parameterIndex, null) it return exception
Caused by: java.sql.SQLException: Query failed : Syntax error at: ,
at com.mapd.jdbc.MapDStatement.executeQuery(MapDStatement.java:69)

the problem is that the mapd not support blank paramters …

someone help me…

Thanks.


#2

Could you share more of your code, or the entire statement you’re trying to execute?

Thanks!


#3

Yes!
`
@Component
public class MapDPreparedStatementParameterSetterImpl implements MapDPreparedStatementParameterSetter {

@Override
public void setParameters(PreparedStatement statement, Object... parameters) 
		throws PreparedStatementParameterSetterException {
	try {
				    
		for (int i = 0, length = parameters.length; i < length; i++) {
	      final Object parameter = parameters[i];
	      final int parameterIndex = i + 1;
	     
	      if (null == parameter){
	    	 
	    	  									//Return type sql in java.sql.Types.<<MyTypeInSql>>	
	    	 statement.setNull(parameterIndex, MeasureColumnTypes.valueOf(parameterIndex).getTypeColumn());
	    	  
	      }
	      
	      
	      else if (parameter instanceof Boolean){
	        //statement.setBoolean(parameterIndex, null);
	      }
	      else if (parameter instanceof Character){
	        statement.setString(parameterIndex, String.valueOf(parameter));
	      }
	      else if (parameter instanceof Byte){
	        statement.setByte(parameterIndex, (Byte) parameter);
	      }
	      else if (parameter instanceof Short){
	        statement.setShort(parameterIndex, (Short) parameter);
	      }
	      else if (parameter instanceof Integer){
	        statement.setInt(parameterIndex, (Integer) parameter);
	      }
	      else if (parameter instanceof Long){
	        statement.setLong(parameterIndex, (Long) parameter);
	      }
	      else if (parameter instanceof Float){
	        statement.setFloat(parameterIndex, (Float) parameter);
	      }
	      else if (parameter instanceof Double){
	        statement.setDouble(parameterIndex, (Double) parameter);
	      }
	      else if (parameter instanceof String){
	        statement.setString(parameterIndex, (String) parameter);
	      }
	      else if (parameter instanceof Date){
	        statement.setDate(parameterIndex, new java.sql.Date(((Date) parameter).getTime()));
	      }
	      else if (parameter instanceof Calendar){
	        statement.setDate(parameterIndex, new java.sql.Date(((Calendar) parameter).getTimeInMillis()));
	      }
	      else if (parameter instanceof BigDecimal){
	        statement.setBigDecimal(parameterIndex, (BigDecimal) parameter);
	      }
	      else{
	        throw new IllegalArgumentException(String.format(
	            "Unknown type of the parameter is found. [param: %s, paramIndex: %s]", parameter, parameterIndex));
	      }
	    }
	  
	} catch (SQLException e) {
		throw new PreparedStatementParameterSetterException(e);
	}
}

}
`

The problem that i try set null value in the mapd through my app java, however the method setNull, set empty value causing the exception:

Caused by: java.sql.SQLException: Query failed : Syntax error at: ,
at com.mapd.jdbc.MapDStatement.executeQuery(MapDStatement.java:69)


@Override public void setNull(int parameterIndex, int sqlType) throws SQLException { //logger.debug("Entered"); parmRep[parameterIndex - 1] = ""; repCount++; }

Can you give it to me the jar file updated ? I need immediate.

Thanks for help me. :grinning:


#4

This was also cross-posted as an issue in GitHub and @RalphLoen provided a fix over there.