- public interface UserInfoDao {
- int insertUserInfoByClob(UserInfo ui);
- UserInfo selectUserInfoClobById(String id);
- }
[java] view
plain copy
- @Test
- public void testInsert() {
- try {
- UserInfo ui = new UserInfo("clob", "3", "clob", "77778888", "0", "clob@email.com", "");
- File file = new File("C://Temp/my.txt");
- FileInputStream fis = new FileInputStream(file);
- byte[] buf = new byte[1024];
- StringBuffer sb = new StringBuffer();
- while ((fis.read(buf)) != -1) {
- sb.append(new String(buf));
- buf = new byte[1024];// 重新生成,避免和上次读取的数据重复
- }
- String cv = new String(sb.toString().getBytes(),"utf-8");
- System.out.println(cv.length());
- ui.setCv(cv);
- UserInfoDao userInfo = sqlSession.getMapper(UserInfoDao.class);
- int re = userInfo.insertUserInfoByClob(ui);
- if (re == 1) {
- System.out.println("success");
- }
- sqlSession.commit();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-------------------------------------------------------------------------------------------------------------------------------------------------------
【注意】
a.本例使用范围为文本类型的文件。
b.文件的格式务必与数据库保持一致,如果不同,请一定在insert之前进行转码操作。如果在控制台输出乱码,那么即使所有配置正确,仍然可能导致插入失败,请各位看官特别注意。
c.如果控制台提示有packet长度不够,请在my.ini文件中修改对应配置,之后请重新启动即可。
--------------------------------------------------------------------------------------------------------------------------------------------------------
刚才我们演示了,insert操作,现在,我们来看看select操作步骤:
1.在Mapper文件中增加查询SQL,如下:
[html] view
plain copy