jiezhi(西域浪子)感谢你的热情
但请明白我说的只读是说结果集不能删除更新只能读取!!!
加不加 rs.updateRow()都是只读的!!!!
但请明白我说的只读是说结果集不能删除更新只能读取!!!
加不加 rs.updateRow()都是只读的!!!!
解决方案 »
- 安装oracle 11g环境变量ORACLE_HOME的一个问题
- sqlplus /nolog和sqlplus之后写用户名密码区别
- oracle 索引失效问题
- 表对象的一些问题
- 这个问题不晓得有没有人会???
- 触发器问题(急)
- 如何在表中实现“id”字段自动加1?我实验过“序列”,但在表中看不到字段啊!!急的哭,在线等啊!
- SQL语句问题,在线等。
- Oracle中查询后结果集的排序问题
- 我64位操作系统,安装oracle12c后,在cmd命令打开显示Windows\system32;并且启动后输入命令都显示:不是内部或外部命令。。。。。。。
- 在oralce中 怎么判断表是否存在?
- 这是什么错误阿?各位
/**
* A simple sample to demonstrate ResultSet.udpateRow().
*/import java.sql.*;public class ResultSet4
{
public static void main(String[] args) throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); String url = "jdbc:oracle:oci8:@";
try {
String url1 = System.getProperty("JDBC_URL");
if (url1 != null)
url = url1;
} catch (Exception e) {
// If there is any security exception, ignore it
// and use the default
} // Connect to the database
Connection conn =
DriverManager.getConnection (url, "scott", "tiger"); // Create a Statement
Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE); // Query the EMP table
ResultSet rset = stmt.executeQuery ("select EMPNO, ENAME, SAL from EMP"); // Give everybody a $500 raise
adjustSalary (rset, 500); // Verify the sarlary changes
System.out.println ("Verify the changes with a new query: ");
rset = stmt.executeQuery ("select EMPNO, ENAME, SAL from EMP");
while (rset.next())
{
System.out.println (rset.getInt(1)+" "+rset.getString(2)+" "+
rset.getInt(3));
}
System.out.println (); // Close the RseultSet
rset.close(); // Close the Statement
stmt.close(); // Cleanup
cleanup(conn); // Close the connection
conn.close();
} /**
* Update the ResultSet content using updateRow().
*/
public static void adjustSalary (ResultSet rset, int raise)
throws SQLException
{
System.out.println ("Give everybody in the EMP table a $500 raise\n"); int salary = 0; while (rset.next ())
{
// save the old value
salary = rset.getInt (3); // update the row
rset.updateInt (3, salary + raise);
// flush the changes to database
rset.updateRow (); // show the changes
System.out.println (rset.getInt(1)+" "+rset.getString(2)+" "+
salary+" -> "+rset.getInt(3));
}
System.out.println ();
} /**
* Generic cleanup.
*/
public static void cleanup (Connection conn) throws SQLException
{
Statement stmt = conn.createStatement ();
stmt.execute ("UPDATE EMP SET SAL = SAL - 500");
stmt.execute ("COMMIT");
stmt.close ();
}
}
你的这段程序可以执行吗
rset.updateInt (3, salary + raise);可以正常更新吗??????
String url1 = System.getProperty("JDBC_URL");是不不因为用了这句????
你的ORACLE板本是多少
????
我的死活不行不管怎么设,总是只读!!!
1。要用oracle jdbc中class12类库,若一定要用class1.x.x类库,则要加import oracle.jdbc2.*;
2。select 语句不能用select * from yourtab 要用select col1,col2,... from yourtab
你用SQLPLUS能更新和写入记录吗。
try{
Class.forName("oracle.jdbc.driver.OracleDriver"); String url = "jdbc:oracle:thin:@pc16oang:1521:ORCL";
String user = "prox";
String password = "prox";
Connection conn = DriverManager.getConnection(url,user,password); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//this ResultSet can been Update,not readonly.
ResultSet rs = stmt.executeQuery("select name,price from fruit");
//rs.first();
rs.last();
rs.updateInt("price",177);
rs.updateRow();
System.out.println("Update had Completed!");
conn.commit(); stmt.close();
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
} }
}