import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.xdb.XMLType;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
public class XmlTypeHandler implements TypeHandler<String> {
* @see org.apache.ibatis.type.TypeHandler#getResult(java.sql.ResultSet,
public String getResult(ResultSet paramResultSet, String paramString)
// TODO Auto-generated method stub
* @see org.apache.ibatis.type.TypeHandler#getResult(java.sql.ResultSet,
public String getResult(ResultSet paramResultSet, int paramInt)
// TODO Auto-generated method stub
* org.apache.ibatis.type.TypeHandler#getResult(java.sql.CallableStatement,
public String getResult(CallableStatement paramCallableStatement,
int paramInt) throws SQLException {
// TODO Auto-generated method stub
* org.apache.ibatis.type.TypeHandler#setParameter(java.sql.PreparedStatement
* , int, java.lang.Object, org.apache.ibatis.type.JdbcType)
public void setParameter(PreparedStatement paramPreparedStatement,
int paramInt, String paramT, JdbcType paramJdbcType)
XMLType data = XMLType.createXML(
paramPreparedStatement.getConnection(), paramT);
paramPreparedStatement.setObject(paramInt, data);
<insert id="insertXMLType" parameterType="path.to.pojo.XMLPojo"
flushCache="true">
INSERT INTO
XML_TABLE
<trim prefix="(" suffix=")" suffixOverrides=",">
#{xmlColumn,jdbcType=VARCHAR,typeHandler=path.to.handler.XmlTypeHandler},
I'm not sure this is the best solution, but it works...
Be careful when you create XMLType, one of the constructor parameters is Connection. In some environments (like WebSphere), you will not be able to get connection via paramPreparedStatement.getConnection(),because the Connection object is wrapped inside some other object (for security reasons)