关于在工程中使用Mybatis来操作XMLType
2014-09-14 15:02
260 查看
最近在项目上要用Mybatis来操作XMLType,经历了种种坎坷,目前还在调研中,先记下一些问题
1. 首先,得到消息是使用Mybatis来操作CLOB数据
翻阅了一下文档,问题非常好解决,利用Mybatis的TypeHandler,重新做了一下处理,就把一个InputStream对象插入到了Oracle数据库中
主要涉及文件,大体上就三个:Mybatis自己的配置文件(Config.xml/Mybatis-config.xml);作转换处理的java类;映射的写sql的xxxMapper.xml
首先,我们要在Config.xml中描述自己用来处理转换的Handler:在这里建立了两个处理类,第二个就是用来将Inputstream类型转换成CLOB的
接着,我们创建指定的处理类:TestFileToClobHandler,注意路径要和前面的包名一致(xx.ssaa.test)
我只需要插入,所以只要在最后的方法内,转换一下将InputStream转成Reader插入即可。
1. 首先,得到消息是使用Mybatis来操作CLOB数据
翻阅了一下文档,问题非常好解决,利用Mybatis的TypeHandler,重新做了一下处理,就把一个InputStream对象插入到了Oracle数据库中
主要涉及文件,大体上就三个:Mybatis自己的配置文件(Config.xml/Mybatis-config.xml);作转换处理的java类;映射的写sql的xxxMapper.xml
首先,我们要在Config.xml中描述自己用来处理转换的Handler:在这里建立了两个处理类,第二个就是用来将Inputstream类型转换成CLOB的
<configuration> <typeAliases> <typeAlias alias="User" type="xx.ssaa.test.model.User"/> <typeAlias alias="User_Oracle" type="xx.ssaa.test.UserOracle"/> </typeAliases> <typeHandlers> <typeHandler javaType="String" jdbcType="INTEGER" handler="xx.ssaa.test.TestChangeHandler" /> <typeHandler javaType="java.io.InputStream" jdbcType="CLOB" handler="xx.ssaa.test.TestFileToClobHandler" /> </typeHandlers>
接着,我们创建指定的处理类:TestFileToClobHandler,注意路径要和前面的包名一致(xx.ssaa.test)
我只需要插入,所以只要在最后的方法内,转换一下将InputStream转成Reader插入即可。
public class TestFileToBlobHandler implements TypeHandler { @Override public Object getResult(ResultSet arg0, String arg1) throws SQLException {
<pre name="code" class="java"><span style="white-space:pre"> </span>// TODO Auto-generated method stub return null;
<span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>@Override public Object getResult(ResultSet arg0, int arg1) throws SQLException { // TODO Auto-generated method stub return null; } @Override public Object getResult(CallableStatement arg0, int arg1) throws SQLException { // TODO Auto-generated method stub return null; } <span style="white-space:pre"> </span>@Override public void setParameter(PreparedStatement arg0, int arg1, Object arg2, JdbcType arg3) throws SQLException { File xfile = (File) arg2; StringBuffer sbInput = new StringBuffer(); String line = null; try { InputStream input = new FileInputStream(xfile); BufferedReader reader = new BufferedReader(new InputStreamReader(input)); <span style="white-space:pre"> </span>} catch (Exception ex) { ex.printStackTrace(); } arg0.setClob(arg1, reader); <span style="white-space:pre"> </span>} }
相关文章推荐
- 关于使用Mybatis逆向工程针对Oracle数据库表生成代码需要注意的问题
- Idea 使用Mybatis逆向工程操作步骤
- SilverLight学习笔记--关于使用IValueConvert对绑定数据的格式化操作
- 关于在存储过程中使用游标操作数据库
- 关于使用JBOSSTOOLS配置SEAM工程
- 关于ASP.NET“操作必须使用一个可更新的查询”问题的解决方法
- 关于使用SHFileOperation做文件操作的问题
- 关于C#中使用SQLDMO来获取数据库中的一些操作
- 关于Qt中使用的工程文件(.pro文件)
- SilverLight学习笔记--关于使用IValueConvert对绑定数据的格式化操作
- 关于在地址本数据库设计中同步内容使用XMLType的技术建议
- 关于VC60中创建MFC工程时, 使用了UNICODE选项后编译报错的解决方法
- 关于使用powerdesigner进行反向工程
- 关于基于FastCGI上构建的PHP,或者使用freetds客户端操作MSSQL时,对ntext取值不显示的说明.
- 关于事件流的操作使用小例
- ASP.Net下如何解决关于Access数据库“操作必须使用一个可更新的查询”问题
- 几个相似的关于操作内存的函数---开始大量使用.
- 使用vs2005经验与教训(关于masterpage,menu,gridview及对exce的l操作)
- 关于ISDN使用R3640路由器进行配置操作实例
- 关于“操作必须使用一个可更新的查询”错误提示!