问题描述
我有大文本,它是字符串格式.我想知道如何将String转换为CLOB.我正在使用Spring数据JPA,Spring Boot.
I have large text which is in String format. I would like to know how to convert that String into CLOB. I'm using Spring data JPA, Spring boot.
我尝试使用
clob.setString(position, string)
推荐答案
在不拖累其他问题的情况下,我想简单地回答一下.
Without dragging the question further I want to answer it simply.
在Spring Data JPA中,应该有一个String实体,需要将其保存为DB中的CLOB.因此,实体的CLOB列应如下所示.
In Spring Data JPA there should be an entity which is String and needed to be saved as CLOB in DB. So, the CLOB column of entity should look like this.
@Entity
public class SampleData {
// other columns
@Column(name="SAMPLE", columnDefinition="CLOB NOT NULL")
@Lob
private String sample;
// setters and getters
}
然后,您应该拥有一个如下所示的存储库
Then you should have a Repository like below
public interface SampleDataRepo extends PagingAndSortingRepository<SampleData, Integer> {
}
现在在Service方法中,您可以执行以下操作
Now in Service method you could do something like below
@Service
public class SampleDataService {
@Autowire
SampleDataRepo repo;
public SampleData saveSampleData() {
SampleData sd = new SampleData();
sd.setSample("longtest");
repo.save(sd);
}
}
这是将String数据保存为DB中的CLOB的方式.
This is how the String data is saved as CLOB in DB.
这篇关于在Spring数据JPA中将String转换为CLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!