云数据库 GaussDB-示例:常用操作:示例3 常用数据类型使用示例

时间:2025-02-12 15:08:41

示例3 常用数据类型使用示例

//bit类型使用示例,注意此处bit类型取值范围[0,1]Statement st = conn.createStatement();String createsql = "create table if not exists t_bit(col_bit bit)";String sqlstr = "create or replace function fun_1()\n" +        "returns bit AS $$\n" +        "select col_bit from t_bit limit 1;\n" +        "$$\n" +        "LANGUAGE SQL;";st.execute(createsql);st.execute(sqlstr);CallableStatement c = conn.prepareCall("{ ? = call fun_1() }");//注册输出类型,位串类型c.registerOutParameter(1, Types.BIT);c.execute();//使用Boolean类型获取结果System.out.println(c.getBoolean(1));// money类型使用示例// 表结构中包含money类型列的使用示例。st.execute("create table t_money(id int,col1 money)");PreparedStatement pstm = conn.prepareStatement("insert into t_money values(1,?)");// 使用PGobject赋值,取值范围[-92233720368547758.08,92233720368547758.07]PGobject minMoney = new PGobject();minMoney.setType("money");minMoney.setValue("-92233720368547758.08");pstm.setObject(1, minMoney);pstm.execute();// 使用PGMoney赋值,取值范围[-9999999.99,9999999.99]pstm.setObject(1,new PGmoney(9999999.99));pstm.execute();

当前JDBC不支持调用返回数据类型为money的存储过程和函数。

support.huaweicloud.com/distributed-devg-v2-gaussdb/gaussdb-12-0066.html