package com.aa.biz.utils.dbtest;
import com.aa.biz.api.workflow.ProcessInitiatorVariable;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.*;
/**
* @Auther: zs
* @Date: 2019/9/20 14:00
* @Description:
*/
public class DBUtils {
public ProcessInitiatorVariable getObj() {
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("url", "name", "pass");
}catch (Exception e){
}
String sql = "select * FROM ACT_GE_BYTEARRAY where id_ = '542607'";
try {
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
//将对应字段转换为流
ObjectInputStream ois = new ObjectInputStream(rs.getBinaryStream("bytes_"));
//将流转换为 对象
ProcessInitiatorVariable process = (ProcessInitiatorVariable) ois.readObject();
return process;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static void main(String[]args){
DBUtils dbUtils = new DBUtils();
ProcessInitiatorVariable process = dbUtils.getObj();
System.out.println(process);
}
}
jdbc 读取mysql数据库里保存的对象
最新推荐文章于 2024-05-08 15:04:33 发布