提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
将Oracle的BLOB类型字段传输到MySQL的LONGTEXT类型字段- 一、相关资料
- 1、POM依赖
- 2、配置文件
- 3、代码
- 4、Oracle数据库
- 5、MySQL数据库
- 6、效果图
- 二、其他
- 1、Maven依赖爆红解决方案
一、相关资料 1、POM依赖
com.baomidou
mybatis-plus-boot-starter
3.2.0
com.oracle
ojdbc6
11.2.0.5
mysql
mysql-connector-java
runtime
2、配置文件
application.properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true spring.datasource.username=root spring.datasource.password=123123
jdbc.properties
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521/orcl jdbc.username=root jdbc.password=1231233、代码
实体类
@TableName("HIS_NHYY")
public class MyTest implements Serializable {
int id;
String text;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@Override
public String toString() {
return "MyTest{" +
"id=" + id +
", text='" + text + ''' +
'}';
}
}
Oracle连接工具类
public class TZDBConn {
private static final String DRIVER = getValue("jdbc.driverClassName");
private static final String URL = getValue("jdbc.url");
private static final String USERNAME = getValue("jdbc.username");
private static final String PASSWORD = getValue("jdbc.password");
private static Connection connection = null;
private static PreparedStatement sta = null;
private static ResultSet rs = null;
private static String getValue(String key) {
// 资源包绑定
ResourceBundle bundle = ResourceBundle.getBundle("jdbc");
return bundle.getString(key);
}
static {
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public Connection getConnection() {
try {
connection = DriverManager.getConnection(URL,USERNAME,PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
public ResultSet Query(String sql, Object...obj){
connection=getConnection();
try {
sta=connection.prepareStatement(sql);
if(obj!=null){
for(int i=0;i getMyTest(String sql) {
List myTestList=new ArrayList<>();
TZDBConn dbconn=new TZDBConn();
try {
rs =dbconn.Query(sql, null);
while(rs.next()){
MyTest myTest=new MyTest();
// myTest.setId(rs.getInt("id"));
Blob blob = rs.getBlob("text");
String content = new String(blob.getBytes(1, (int)blob.length()),"GBK");
myTest.setText(content);
myTestList.add(myTest);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
close();
}
return myTestList;
}
}
持久层
public interface TextDao extends baseMapper{ }
测试代码
@SpringBootTest
class MySpringboot2ApplicationTests {
private TZDBConn tzDBConn = new TZDBConn();
@Autowired
TextDao textDao;
@Test
void oracleTest() {
String sql="SELECt * FROM HIS_NHYY";
List myTest = tzDBConn.getMyTest(sql);
for(MyTest s:myTest){
textDao.insert(s);
}
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper
// .select("id", "name", "age")
.eq("id", 2);
// .like("name", "j");
List userInfos = textDao.selectList(queryWrapper);
userInfos.forEach(System.out::println);
}
}
启动类
@SpringBootApplication
@MapperScan("com.example.myspringboot2.dao")
public class MySpringboot2Application {
public static void main(String[] args) {
SpringApplication.run(MySpringboot2Application.class, args);
}
}
4、Oracle数据库
5、MySQL数据库
6、效果图
二、其他
1、Maven依赖爆红解决方案
链接地址
举例
下载Oracle依赖到本地我是放在D:学习Oracleojdbc6.jar
#我在该地址使用cmd C:Users13113.m2wrapperdistsapache-maven-3.6.3-bin1iopthnavndlasol9gbrbg6bf2apache-maven-3.6.3bin #注意:不能把jar包放在本地仓库目录里,会报错的 mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.5 -Dpackaging=jar -Dfile=D:学习Oracleojdbc6.jar



