ibatis及jdbc存取clob类型数据

阅读更多

1.通过jdbc方式存储clob类型数据

private void updateJdbcStudById(SqlMapClient sqlmap, Map inmap){
	String infos = (String)inmap.get("infos");
	//字符串类型的clob类型
	Reader reader = new StringReader(infos);
	try {
		Connection conn = sqlmap.getDataSource().getConnection();
		String sql = "update student set informations = ? where stuno = ?";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		//为clob类型赋值
		ps.setCharacterStream(1, reader, infos.length());
		ps.setString(2, (String)inmap.get("stuno"));
		ps.execute();
		
		ps.close();
		conn.close();
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

 

2.通过ibatis存取clob类型数据

informations字段配置

private List queryStudentById(SqlMapClient sqlmap, String studno){
	List lists = new ArrayList();
	try {
		lists = sqlmap.queryForList("queryStdById", studno);
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return lists;
}

 配置文件如下

  

	
	
		
		
		
		
		
		
	
    
    
    
    
    
     update student set informations = #infos,javaType=String,jdbcType=CLOB# where stuno = #stuno#
    

 附相关的驱动包

 

  • ojdbc6.jar (1.9 MB)
  • 下载次数: 0
  • classes12.jar (1.5 MB)
  • 下载次数: 0
  • ojdbc14.jar (1.1 MB)
  • 下载次数: 0

你可能感兴趣的:(ibatis及jdbc存取clob类型数据)