使用JdbcRowSet对象进行更新时出现异常

时间:2014-05-15 01:30:20

标签: java jdbc

当我在程序下运行时,我在更新RowSet时遇到异常 但是scrollable工作正常。 JdbcRowSet默认是可更新和可滚动的吗?

       java.sql.SQLException: ResultSet is not updatable
        at com.sun.rowset.JdbcRowSetImpl.checkTypeConcurrency(Unknown Source)
        at com.sun.rowset.JdbcRowSetImpl.updateString(Unknown Source)
        at JdbcRowSet_Example.<init>(JdbcRowSet_Example.java:66)
        at JdbcRowSet_Example.main(JdbcRowSet_Example.java:77)

代码段

import com.sun.rowset.JdbcRowSetImpl;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import javax.sql.rowset.JdbcRowSet;




public class JdbcRowSet_Example {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url= "jdbc:oracle:thin:@192.168.1.102:1521:orcl";
    String userName = "scott";
    String passWord = "tiger";

    public JdbcRowSet_Example() throws Exception {
        Class.forName(driver);
        JdbcRowSet jrs = new JdbcRowSetImpl();
        jrs.setCommand("select * from Registration");
        jrs.setUrl(url);
        jrs.setUsername(userName);
        jrs.setPassword(passWord);

        jrs.execute();

        ResultSetMetaData rsmd = jrs.getMetaData();
        int count = rsmd.getColumnCount();
        System.out.println("Number of Columns" + count);



        System.out.println("Scrollable Example");

        jrs.absolute(2);
        for(int i=1; i<=count; i++){
            System.out.print(jrs.getString(i) + "\t" + "\t"+"\t");
            }
        System.out.println();

        System.out.println("Updatable Example");


        jrs.absolute(4);


        jrs.updateString(1, "Reyansh");
        jrs.updateString(2,"Gogula");
        jrs.updateString(3,"Rey_Gogula@hotmail.com");
        jrs.updateRow();
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            JdbcRowSet_Example jd = new JdbcRowSet_Example();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

1 个答案:

答案 0 :(得分:1)

将查询更改为: 选择注册。* FROM注册;

我知道这看起来很愚蠢,但效果很好!