I'm trying to put a lengthy WKT (a long string about geographical info) into an oracle spatial function SDO_GEOMETRY
to transform WKT into oracle geometry type using mybatis. There are no column in the database that stores the WKT, it is only used as a parameter in the said function. The java type of the item is String
, when I try to put it in it would return error, saying String too long. This indicates that the string is not being turned into a CLOB. How do I do that?
I tried using this at the start of mybatis .xml file:
<resultMap type="example.Building" id="BaseResultMap">
<result property="geom" column="geom" jdbcType="CLOB"
javaType = "java.lang.String" typeHandler ="example.Utils.OracleClobTypeHandler"/>
</resultMap>
and I have an OracleClobTypeHandler
class set up.
I also tried using #{wkt,jdbcType=CLOB}
but that went nowhere.
EDIT: This is the SetParameter
method in the OracleClobTypeHandler
:
@Override
public void setParameter(PreparedStatement arg0, int arg1, Object arg2, JdbcType arg3) throws SQLException {
CLOB clob = CLOB.getEmptyCLOB();
clob.setString(1, (String) arg2);
arg0.setClob(arg1, clob);
}
<resultMap />
is irrelevant as it is used when mapping query result to Java object.
Try specifying typeHandler in the parameter reference. e.g.
#{wkt,typeHandler=example.Utils.OracleClobTypeHandler}
Note that if the type handler is an inner class of Utils
, it has to be referenced as example.Utils$OracleClobTypeHandler
instead.