简体   繁体   English

如何在使用oracle函数时将参数作为CLOB传递给mybatis?

[英]How to pass arguments as CLOB in mybatis while using oracle functions?

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. 我正在尝试将一个冗长的WKT(一个关于地理信息的长字符串)放入一个oracle空间函数SDO_GEOMETRY以使用mybatis将WKT转换为oracle几何类型。 There are no column in the database that stores the WKT, it is only used as a parameter in the said function. 数据库中没有存储WKT的列,它仅用作所述函数中的参数。 The java type of the item is String , when I try to put it in it would return error, saying String too long. 该项的java类型是String ,当我尝试将其放入其中时会返回错误,说String太长。 This indicates that the string is not being turned into a CLOB. 这表示该字符串未转换为CLOB。 How do I do that? 我怎么做?

I tried using this at the start of mybatis .xml file: 我尝试在mybatis .xml文件的开头使用它:

<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. 我设置了一个OracleClobTypeHandler类。

I also tried using #{wkt,jdbcType=CLOB} but that went nowhere. 我也尝试使用#{wkt,jdbcType=CLOB}但这无处可去。

EDIT: This is the SetParameter method in the OracleClobTypeHandler : 编辑:这是OracleClobTypeHandlerSetParameter方法:

    @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. <resultMap />与将查询结果映射到Java对象时使用无关。
Try specifying typeHandler in the parameter reference. 尝试在参数引用中指定typeHandler。 eg 例如
#{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. 请注意,如果类型处理程序是Utils的内部类,则必须将其引用为example.Utils$OracleClobTypeHandler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM