Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting int[] into PostgreSql with iBatis
    text
    copied!<p>... is there an easy way to insert a Java int[] into PostgreSql with the help of iBatis? (the older one, not the new MyBatis)</p> <p>Not sure if I DO need a custom type handler or not, but I'm having a difficult time finding a code sample that would illustrate what's going on.</p> <p>Thanks in advance.</p> <p>ps:</p> <p>since the original posting, I'm able to read the array from DB and populate the int[] in the domain object. But can't write to the db yet :-(</p> <p>so in the domain model there's:</p> <pre><code>int[] crap = null; </code></pre> <p>with getters and setters, cusom property handler looks like this:</p> <pre><code>public class ArrayTypeHandler implements TypeHandlerCallback { public void setParameter(ParameterSetter setter, Object parameter) throws SQLException { if( parameter == null){ setter.setNull( Types.ARRAY); } else { setter.setArray( (Array) Arrays.asList(parameter ) ); } } public Object getResult(ResultGetter getter) throws SQLException { Array array = getter.getResultSet().getArray(getter.getColumnName()); if( !getter.getResultSet().wasNull()){ return array.getArray(); } else { return null; } } public Object valueOf(String string) { throw new UnsupportedOperationException("Not supported yet."); } </code></pre> <p>}</p> <p>sqlMapConfig.xml:</p> <pre><code>&lt;typeHandler javaType="java.sql.Array" jdbcType="ARRAY" callback="project.persistance.sqlmapdao.ArrayTypeHandler" /&gt; </code></pre> <p>When trying to update i get the following error:</p> <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; </code></pre> <p>--- The error occurred in project/persistance/sql_xml/Article.xml.<br> --- The error occurred while applying a parameter map.<br> --- Check the updateArticle-InlineParameterMap.<br> --- Check the parameter mapping for the 'crap' property.<br> --- Cause: java.lang.NullPointerException; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:<br> --- The error occurred in project/persistance/sql_xml/Article.xml.<br> --- The error occurred while applying a parameter map.<br> --- Check the updateArticle-InlineParameterMap.<br> --- Check the parameter mapping for the 'crap' property.<br> --- Cause: java.lang.NullPointerException</p> <p>... any hints as to what I'm missing? thanks</p> <p>===</p> <p>... worked my way up to ClassCastExceptiong :-)</p> <p>trying to set the propery:</p> <pre><code> public void setParameter(ParameterSetter setter, Object parameter) throws SQLException { int[] c = (int[]) parameter; setter.setArray( (java.sql.Array) c ); } </code></pre> <p>... and the ensuing exception:</p> <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; </code></pre> <p>--- The error occurred in project/persistance/sql_xml/Article.xml.<br> --- The error occurred while applying a parameter map.<br> --- Check the updateArticle-InlineParameterMap.<br> --- Check the parameter mapping for the 'crap' property.<br> --- Cause: java.lang.ClassCastException: java.util.ArrayList; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:<br> --- The error occurred in project/persistance/sql_xml/Article.xml.<br> --- The error occurred while applying a parameter map.<br> --- Check the updateArticle-InlineParameterMap.<br> --- Check the parameter mapping for the 'crap' property.<br> --- Cause: java.lang.ClassCastException: java.util.ArrayList</p> <p>... I've had it today though. Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload