zoukankan      html  css  js  c++  java
  • JDBC 可更新和对更新敏感的结果集

    public class OtherApi {

        /**
         * @param args
         * @throws SQLException
         * @throws InterruptedException
         */
        public static void main(String[] args) throws SQLException,
                InterruptedException {
            read();
        }

        static void read() throws SQLException, InterruptedException {
            Connection conn = null;
            Statement st = null;
            ResultSet rs = null;
            try {
                // 2.建立连接
                conn = JdbcUtils.getConnection();
                // conn = JdbcUtilsSing.getInstance().getConnection();
                // 3.创建语句
                st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,//第一个参数表示可滚动,INSENSITIVE表示对更新不敏感,SENSITIVE敏感
                        ResultSet.CONCUR_UPDATABLE);//第二个参数,表示结果集可更新

                // 4.执行语句
                rs = st
                        .executeQuery("select id, name, money, birthday  from user where id < 5");

                // 5.处理结果
                while (rs.next()) {
                    int id = rs.getInt("id");
                    System.out.println("show " + id + "...");
                    Thread.sleep(10000);//在这十秒钟手动修改下一条数据,如果数据库引擎支持更新敏感,那么结果集也会重新去查询数据库取得最新数据,由于Mysql不支持更新敏感,所以上面第二个参数没有起效果
                    System.out.println(id + " " + rs.getObject("name") + " "
                            + rs.getObject("birthday") + " "
                            + rs.getObject("money"));
                   
                    if("1".equals(id)) {
                        rs.updateFloat("money", 300f);//上面的第二个参数,导致这个地方可以更新到数据库里
                        rs.updateRow();
                    }
                }
            } finally {
                JdbcUtils.free(rs, st, conn);
            }
        }

    }

  • 相关阅读:
    GeoServer开发手册
    如何自行分析定位SAP BSP错误
    SAP CRM里的user parameter之COM_IOITF_DEBUG
    SAP One Order应用的跟踪工具CRMD_TRACE_SET
    明明没有发生超时错误,为什么SAP WebClient UI会显示超时错误提示?
    使用ABAP SE16查看类型为RAWSTRING的数据库列字段值
    SAP CRM附件模型和搜索相关的属性介绍
    SAP WebClient UI和business switch相关的逻辑介绍
    SAP WebClient UI页面标签的决定逻辑介绍
    SAP WebClient UI配置决定(configuration)的逻辑介绍
  • 原文地址:https://www.cnblogs.com/flying607/p/3462547.html
Copyright © 2011-2022 走看看