将json原型 key value保存数据库并且取出

简介: 将json原型 key value保存数据库并且取出
package test;
import com.google.gson.JsonObject;
import org.apache.commons.dbcp2.DriverConnectionFactory;
import java.io.InputStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) throws  Exception {
    Connection connection=getConnection();
    ResultSet re =  connection.prepareStatement("select * from users ").executeQuery();
 //   int res =  connection.prepareStatement("insert  into users values(4,'{\"name\":\"123445\"}')").executeUpdate();
   // System.out.println(res+"==================");
    List<String> list=new ArrayList<>();
    while (re.next()){
        InputStream in=re.getBinaryStream("shopInfo");
        byte[] bytes=new byte[1024];
        StringBuffer stringBuffer=new StringBuffer();
        while (in.read(bytes)!=-1){
            System.out.println(new String(bytes));
            stringBuffer.append(new String(bytes));
        }
        list.add(stringBuffer.toString());
    }
    for (String s :list) {
// JSONObject obj= JSON.parseObject(s);
// System.out.println(obj.get(“sex”)+”==============_=-“);
}
re.close();
ResultSet ree = connection.prepareStatement(“select * from users “).executeQuery();
while (ree.next()){
Blob blob =ree.getBlob(“shopInfo”);
byte[] bytes=new byte[1024];
InputStream in=blob.getBinaryStream();
while (in.read(bytes)!=-1){
System.out.println(new String(bytes));
}
}
ree.close();
    connection.close();
}
public static Connection getConnection()throws Exception{
    Class.forName("com.mysql.jdbc.Driver");
    Connection connection= DriverManager.getConnection("jdbc:mysql://localhost:xxxx/xxxx?useSSL=false&amp;useUnicode=true&amp;characterEncoding=utf8&amp;autoReconnect=true&amp;failOverReadOnly=false","root","12ewerwr34");
    return connection;
}


相关文章
|
4月前
|
存储 JSON 关系型数据库
Pandas载入txt、csv、Excel、JSON、数据库文件讲解及实战(超详细 附源码)
Pandas载入txt、csv、Excel、JSON、数据库文件讲解及实战(超详细 附源码)
66 0
|
1月前
|
JSON 大数据 数据格式
web后端-json递归获取key值
web后端-json递归获取key值
|
7月前
|
JSON Java 数据格式
Java将json中key值下划线转为驼峰格式
Java将json中key值下划线转为驼峰格式
345 1
|
9月前
|
SQL JSON API
PHP读取数据库记录转换为JSON的代码(API接口的SQL语句)
PHP读取数据库记录转换为JSON的代码(API接口的SQL语句)
85 0
|
7月前
|
JSON JavaScript 数据格式
js遍历json的key并打印
js遍历json的key并打印
129 0
|
9月前
|
JSON 关系型数据库 MySQL
漏刻有时API接口实战开发系列(7):PHP将API获取的json数据自动同步到mysql数据库的解决方案
漏刻有时API接口实战开发系列(7):PHP将API获取的json数据自动同步到mysql数据库的解决方案
321 0
|
10月前
|
XML JSON 人工智能
springboot工程中调用第三方接口json数据定时存入数据库
springboot工程中调用第三方接口json数据定时存入数据库
|
11月前
|
JSON JavaScript 数据格式
Js 将JSON内部key值转换大小写和首字母大写
Js 将JSON内部key值转换大小写和首字母大写
251 0
|
11月前
|
数据采集 JSON 算法
如何快速从深层嵌套 JSON 中找到特定的 Key
如何快速从深层嵌套 JSON 中找到特定的 Key
436 0
|
11月前
|
JSON Linux 开发工具
linux下提取日志文件中的某一行JSON数据中的指定Key
linux下提取日志文件中的某一行JSON数据中的指定Key
119 0