测试CLOB和BLOB文本大对象和二进制大对象的一些基本使用

本文介绍了如何进行CLOB和BLOB数据类型的测试,包括将字符串和文件内容存入CLOB字段,以及从数据库中读取CLOB数据。同时,也探讨了BLOB二进制大对象的基本操作。
摘要由CSDN通过智能技术生成

测试CLOB和BLOB文本大对象和二进制大对象的一些基本使用

测试CLOB的基本用法包含将字符串,文件内容插入到数据库中的CLOB字段中,或者将CLOB字段中的值取出来

package cn.com.jdbc;

import java.io.*;
import java.sql.*;

@SuppressWarnings("all")
public class Demo09 {
   
    //测试CLOB 文本大对象的使用 包含将字符串,
    // 文件内容插入到数据库中的CLOB字段中,或者将CLOB字段中的值取出来
    public static void main(String[] args) {
   
        Connection c = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        Reader r = null;
        try {
   
            Class.forName("com.mysql.jdbc.Driver");
            c = DriverManager.getConnection
                    ("jdbc:mysql://localhost:3306/testjdbc","root","123456");
//            ps = c.prepareStatement("insert into t_user2(username,myinfo) values(?,?)");
//            ps.setString(1,"小明");
            //将文本文件内容直接输入到数据库中
//            ps.setClob(2,new FileReader("F:/a.txt"));

            //将程序中的字符串输入到数据库中的Clob字段中
//            ps.setClob(2,new BufferedReader(new InputStreamReader(new ByteArrayInputStream("zxcvbn".getBytes()))));
//            ps.executeUpdate();

//            ps = c.prepareStatement("select * from t_user2 where id = ?");
//            ps.setObject(1,"1009");
//            rs = ps.executeQuery();
//            while(rs.next()) {
   
//               Clob clob = rs.getClob("myinfo");
//               Reader r = clob.getCharacterStream();
//               int tmp;
//               while((tmp = r.read()) != -1) {
   
//                   System.out.print((char)tmp);
//               }
//            }

            ps = c.prepareStatement("select * from t_user2 where id > ?");
            ps.setObject(1,"1009");
            rs = ps.executeQuery()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值