zoukankan      html  css  js  c++  java
  • [Java] JDBC 08 处理可更新的结果集 (sun提供了这样的接口,但是不见得所有的数据库厂商都支持)

    import java.sql.*;
    
    public class TestUpdataRs {
        public static void main(String args[]) {
    
            try {
                new com.mysql.jdbc.Driver();
    
                String url = "jdbc:mysql://localhost/mydata?user=root&password=root";
    
                Connection conn = DriverManager.getConnection(url);
    
                Statement stmt = conn.createStatement(
                        ResultSet.TYPE_SCROLL_INSENSITIVE,
                        ResultSet.CONCUR_UPDATABLE);
    
                ResultSet rs = stmt.executeQuery("select * from emp2");
    
                rs.next();
                // 更新一行数据
                rs.updateString("ename", "AAA"); // 内存中更改了
                rs.updateRow(); // 数据库中真的更改了
    
                // 插入新行
                rs.moveToInsertRow();
                 rs.updateInt(1, 99997);
                rs.updateString("ename", "AAAA");
                rs.updateInt("mgr", 7839);
                rs.updateDouble("sal", 99.99);
                rs.insertRow();
                // 将光标移动到新建的行
                rs.moveToCurrentRow();
    
                // 删除行
                rs.absolute(5);
                rs.deleteRow();
    
                // 取消更新
                // rs.cancelRowUpdates();
    
            } catch (SQLException e) {
                e.printStackTrace();
            }
    
        }
    }
    

  • 相关阅读:
    poj3660 最短路/拓扑序
    poj1502 最短路
    poj3259 最短路判环
    poj1680 最短路判环
    一些自己常用的cdn
    bower
    vuejs点滴
    jquery的ajax
    jquery点滴
    githubpage+hexo构建自己的个人博客
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786573.html
Copyright © 2011-2022 走看看