美文网首页
springjdbc 返回单列数据及Blob类型的写入

springjdbc 返回单列数据及Blob类型的写入

作者: 不知不怪 | 来源:发表于2018-11-28 16:11 被阅读0次

1.返回单列结果时使用SingleColumnRowMapper

        String sql="SELECT id FROM table ";
        List<Long>=jdbcTemplate.query(sb.toString(), new SingleColumnRowMapper<Long>());

2.Blob类型的写入

import java.sql.Types;
.............
.............
        String sql = "insert into base_test (id,name,remark) values(?,?,?)";
        Object[] params = { 1, "张三丰", new SqlLobValue("中国".getBytes()) };
        jdbcTemplate.update(sql.toString(), params, new int[] { Types.INTEGER, Types.VARCHAR, Types.BLOB });
.............
.............

public class TestUser {

    private Integer id;
    private String name;
    private byte[] remark;

2.Blob读取用byte[]字节数组

代码生成器源码

代码生成器演示

spring boot 2.x 实例源码

相关文章

网友评论

      本文标题:springjdbc 返回单列数据及Blob类型的写入

      本文链接:https://www.haomeiwen.com/subject/ecczqqtx.html