关于ResultSet的插入行问题
各位好!我今天在操作ResultSet的插入行时程序报错,还请大家帮帮忙解决下,具体程序代码和报错信息如下所示。
报错信息:
java.sql.SQLException: ORA-01732: data manipulation operation not legal on this view
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:623)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStatement.java:543)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1028)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2888)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:2960)
at oracle.jdbc.driver.UpdatableResultSet.execute_insertRow(UpdatableResultSet.java:2217)
at oracle.jdbc.driver.UpdatableResultSet.insertRow(UpdatableResultSet.java:1499)
at com.bean.JdbcDemo4.insertResult(JdbcDemo4.java:77)
at com.bean.JdbcDemo4.main(JdbcDemo4.java:100)
程序代码:
package com.bean;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JdbcDemo4 {
private static Connection con;
private static PreparedStatement pstmt;
private static ResultSet rs;
//获得结果集
public static void getResult(){
try {
Class.forName("oracle.jdbc.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "shop", "shop");
String sql="select id,name,gender from employees order by id";
pstmt=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=pstmt.executeQuery();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
//显示结果集
public static void showResult(){
try {
System.out.println("ID\t姓名\t性别");
while(rs.next()){
int id=rs.getInt("id");
String name=rs.getString("name");
String gender=rs.getString("gender");
System.out.println(id+"\t"+name+"\t"+gender);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
//关闭资源
public static void closeAll(){
try {
rs.close();
pstmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
//滚动
public static void srollResult(){
try {
rs.last();//滚动到最后一行
rs.previous();//上移一行
rs.first();//回到第一行
rs.beforeFirst();//第一行
rs.absolute(-3);//倒数第三行
rs.absolute(3);//正数第三行
rs.relative(-1);//上移一行
rs.relative(-2);//上移二行
} catch (SQLException e) {
e.printStackTrace();
}
}
//插入行
public static void insertResult() {
try {
rs.moveToInsertRow();
rs.updateInt("id",5);
rs.updateString("name","小强");
rs.updateString("gender","女");
rs.insertRow();
rs.moveToCurrentRow();
} catch&nb