达梦数据库中,text类型字段会自动转换为cloud类型字段。因此,当您使用map接收text类型字段时,达梦数据库会将该字段的数据类型转换为cloud类型,导致数据类型错误。如果您需要在map中接收text类型字段,请将该字段的数据类型在查询语句中指定为text类型。例如,假设您的查询语句为SELECT name, CAST(content AS TEXT) FROM table_name,其中content是text类型字段,您可以使用CAST函数将其转换为text类型,然后在map中接收。
达梦数据库中的text类型是一种LOB(Large Object),用于存储大量的文本数据。而clob也是一种LOB类型,用于存储字符型数据。在达梦数据库中,text类型字段会被自动转换为clob类型,因为它们都属于LOB类型,并且具有相似的特性。这种转换可能会发生在查询、插入、更新等操作中,如果您需要明确使用text类型,建议在SQL语句中显式地指定该字段为text类型,以避免数据类型错误。
Map<String, Object> entity = this.genericMapper.getRecordMapById(formTable, recordId);
while(var3.hasNext()) {
String key = (String)var3.next();
if (itemx.get(key) instanceof ClobProxyImpl) {
ClobProxyImpl clobProxy = (ClobProxyImpl)itemx.get(key);
itemx.put(key, OracleUtils.clobToString(clobProxy));
} else if (itemx.get(key) instanceof Blob) {
Blob blob = (Blob)itemx.get(key);
itemx.put(key, OracleUtils.blobToString(blob));
}
}
package com.jinw.utils;
import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.SQLException;
/**
* @ClassName OracleUtils
* @Description 一句话描述类的作用
* @Author liux
* @Date 2021/12/22 16:22
**/
public class OracleUtils {
public static String clobToString(ClobProxyImpl clobProxy) throws SQLException {
String subString = clobProxy.getSubString(1, (int) clobProxy.length());
return subString;
}
public static String blobToString(Blob blob) throws Exception {
String newStr = "";
int blobLength = (int) blob.length();
byte[] bytes = blob.getBytes(1, blobLength);
if(bytes == null || blobLength == 0){
return "";
}else {
int i = 1;
while(i < blobLength){
bytes = blob.getBytes(i,1024);
i = i + 1024;
newStr = newStr + new String(bytes,"UTF-8");
}
}
return newStr;
}
}
package com.jinw.utils;
import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.SQLException;
/**
* @ClassName OracleUtils
* @Description 一句话描述类的作用
* @Author liux
* @Date 2021/12/22 16:22
**/
public class OracleUtils {
public static String clobToString(ClobProxyImpl clobProxy) throws SQLException {
String subString = clobProxy.getSubString(1, (int) clobProxy.length());
return subString;
}
public static String blobToString(Blob blob) throws Exception {
String newStr = "";
int blobLength = (int) blob.length();
byte[] bytes = blob.getBytes(1, blobLength);
if(bytes == null || blobLength == 0){
return "";
}else {
int i = 1;
while(i < blobLength){
bytes = blob.getBytes(i,1024);
i = i + 1024;
newStr = newStr + new String(bytes,"UTF-8");
}
}
return newStr;
}
}