POSTGRESQL JDBC 写多个条件 其中的关联是 &
现在JSON是越来越多了,也得研究下这些支持了JSON的数据库到底如何读写JSON了,毕竟关系型还是及其常用的啊
import groovy.json.JsonOutput
import groovy.json.StringEscapeUtils
import groovy.sql.Sql
class read_pg {
def readpg() {
def connpg = new conn_pg()
def conn = connpg.db_conn
//按照正常数据库字段输出测试
def sql = """
select a.*,to_timestamp(aa->>'时间' ,'yyyy-mm-ddThh24:mi:ss' ) as time from temp_json a where a.aa->>'时间' like '%T%'
"""
conn.eachRow(sql) {
println(it)
}
println("----------")
//按照数据库输出JSON字段输出测试
sql = """
select a.aa from temp_json a where a.aa->>'时间' like '%T%'
"""
conn.eachRow(sql) { row ->
println(row)
def slurper = new groovy.json.JsonSlurper()
def json = slurper.parseText(row[0].toString())
println(json)
println(json.char)
// #将Unicode转为中文

该文章展示了如何使用Groovy的JDBC连接PostgreSQL数据库,对包含JSON的表进行读写操作。代码示例包括查询JSON字段并转换为Timestamp,以及将包含中文的数据写入JSON列。
最低0.47元/天 解锁文章
1999

被折叠的 条评论
为什么被折叠?



