Mysql读取blob案例:
/**
* 连接mysql查询blob类型的字段测试
* tab为blob类型数据:注意要根据数据库的编码转为编码不然读出来的数据是不对的。
* 2:读取blob时需要从第一个字节开始获取字节
* 测试结果:tab:中国 ==========
*/
public void getStringByBlob() throws Exception {
Connection conn = DBUtil.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select tab from tab");
while (rs.next()) {
Blob result = rs.getBlob("tab");
System.out.println(result);//看不明白啥东西不管
System.out.println(result.length() + "====");//6个字节,汉字utf-8一个字3个字节
if (result != null) {
// getBytes解释
// pos the ordinal position of the first byte in the BLOB value to be extracted; the first byte is at position 1
//