下载ibatis(2.16)以前的版本不行
下载驱动(oracle10g)以前的版本好象也不行
所用oracle版本9i
创建表create table clobtable(id int,content clob);
TestClob.java源码
import java.io.Reader;
import java.util.List;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
public class TestClob {
public static void main(String [] args) throws Exception
{
String resource="sql-map-config.xml";
Reader reader;
reader=Resources.getResourceAsReader(resource);
SqlMapClient sqlmap = SqlMapClientBuilder.buildSqlMapClient(reader);
Clobtable clob=new Clobtable();
StringBuffer value=new StringBuffer("");
for(int i=0;i<20000;i++)
{
value.append("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
}
value.append("");
clob.setContent(value.toString());
clob.setId(2);
sqlmap.insert("insertClobtable",clob);
sqlmap.update("updateClobtable",clob);
Clobtable clob1=new Clobtable();
List list=sqlmap.queryForList("selectClobtable",clob1);
for(int i=0;i<list.size();i++)
{
clob1=(Clobtable)list.get(i);
System.out.println(new String(clob1.getContent()).length());
}
}
public static void main(String [] args) throws Exception
{
String resource="sql-map-config.xml";
Reader reader;
reader=Resources.getResourceAsReader(resource);
SqlMapClient sqlmap = SqlMapClientBuilder.buildSqlMapClient(reader);
Clobtable clob=new Clobtable();
StringBuffer value=new StringBuffer("");
for(int i=0;i<20000;i++)
{
value.append("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
}
value.append("");
clob.setContent(value.toString());
clob.setId(2);
sqlmap.insert("insertClobtable",clob);
sqlmap.update("updateClobtable",clob);
Clobtable clob1=new Clobtable();
List list=sqlmap.queryForList("selectClobtable",clob1);
for(int i=0;i<list.size();i++)
{
clob1=(Clobtable)list.get(i);
System.out.println(new String(clob1.getContent()).length());
}
}
}
Clobtable.java
public class Clobtable {
private int id;
private String content;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
sql-map-config.xml源程序
<?xml version="1.0" encoding="UTF-8"?>
<sqlMapConfig>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="JDBC.ConnectionURL" value="jdbc:oracle:thin:@localhost:1521:cgj"></property>
<property name="JDBC.Username" value="test"></property>
<property name="JDBC.Password" value="test"></property>
<property name="Pool.MaximumActiveConnections" value="10"/>
<property name="Pool.MaximumIdleConnections" value="5"/>
<property name="Pool.MaximumCheckoutTime" value="120000"/>
<property name="Pool.TimeToWait" value="500"/>
<property name="Pool.PingQuery" value="select 1 from clobtable"/>
<property name="Pool.PingEnabled" value="false"/>
<property name="Pool.PingConnectionsOlderThan" value="1"/>
<property name="Pool.PingConnectionsNotUsedFor" value="1"/>
</dataSource>
</transactionManager>
<sqlMap resource="Item.xml"/>
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="JDBC.ConnectionURL" value="jdbc:oracle:thin:@localhost:1521:cgj"></property>
<property name="JDBC.Username" value="test"></property>
<property name="JDBC.Password" value="test"></property>
<property name="Pool.MaximumActiveConnections" value="10"/>
<property name="Pool.MaximumIdleConnections" value="5"/>
<property name="Pool.MaximumCheckoutTime" value="120000"/>
<property name="Pool.TimeToWait" value="500"/>
<property name="Pool.PingQuery" value="select 1 from clobtable"/>
<property name="Pool.PingEnabled" value="false"/>
<property name="Pool.PingConnectionsOlderThan" value="1"/>
<property name="Pool.PingConnectionsNotUsedFor" value="1"/>
</dataSource>
</transactionManager>
<sqlMap resource="Item.xml"/>
</sqlMapConfig>
Item.xml源程序
<?xml version="1.0" encoding="UTF-8"?>
<sqlMap namespace="Plan">
<sqlMap namespace="Plan">
<typeAlias alias="Clobtablea" type="Clobtable"/>
<parameterMap id="ClobtableParam" class="Clobtablea">
<parameter property="id" mode="INOUT"/>
<parameter property="content" jdbcType="CLOB" mode="INOUT"/>
</parameterMap>
<parameter property="id" mode="INOUT"/>
<parameter property="content" jdbcType="CLOB" mode="INOUT"/>
</parameterMap>
<parameterMap id="ClobtableParamUpdate" class="Clobtablea">
<parameter property="content" jdbcType="CLOB" mode="INOUT"/>
<parameter property="id" mode="INOUT"/>
</parameterMap>
<parameter property="content" jdbcType="CLOB" mode="INOUT"/>
<parameter property="id" mode="INOUT"/>
</parameterMap>
<insert id="insertClobtable" parameterMap="ClobtableParam">
insert into clobtable(id,content)
values
(
?,
?
)
</insert>
<select id="selectClobtable" parameterClass="Clobtablea" resultClass="Clobtablea">
select id, content
from clobtable
</select>
<update id="updateClobtable" parameterMap="ClobtableParamUpdate">
update clobtable set content=? where id=?
</update>
</sqlMap>
blob操作只须把content的类型从String改成byte[ ]
insert into clobtable(id,content)
values
(
?,
?
)
</insert>
<select id="selectClobtable" parameterClass="Clobtablea" resultClass="Clobtablea">
select id, content
from clobtable
</select>
<update id="updateClobtable" parameterMap="ClobtableParamUpdate">
update clobtable set content=? where id=?
</update>
</sqlMap>
blob操作只须把content的类型从String改成byte[ ]