在jdbc连接oracle中,为什么添加行显示不出来?

liq1979 2011-04-28 03:09:45
别的例如更新、删除都能显示出来,怎么插入新行(如下,插入编号为8)就不能显示呢?
/// import the JDBC packages
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.*;

public class AdvResultSet{

public static void main (String args [])
throws SQLException {

// register the Oracle JDBC drivers
DriverManager.registerDriver(
new oracle.jdbc.OracleDriver()
);

// create a Connection object, and connect to the database
// as store_user using the Oracle JDBC Thin driver
Connection myConnection = DriverManager.getConnection(
"jdbcracle:thin:@zyj:1521radb",
"zyj",
"zyj"
);

// disable auto-commit mode
myConnection.setAutoCommit(false);

// create a Statement object from which an updatable
// ResultSet object will be created
Statement myStatement = myConnection.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE
);

// create a ResultSet object
ResultSet customerResultSet = myStatement.executeQuery(
"SELECT (编号),(型号),(厂家)" +
"FROM 主机"
);
System.out.println("Retrieved rows from 主机 table";

// update row #2's first name and dob
System.out.println("Updating the 型号 row #2";
customerResultSet.absolute(2);
String new型号 = "Greg";
customerResultSet.updateString("型号", new型号);
customerResultSet.updateRow();

// display the new first name and dob

System.out.println("型号 = " + customerResultSet.getString("型号");

// delete row #5
System.out.println("Deleting row #5";
customerResultSet.absolute(5);
customerResultSet.deleteRow();

// insert a new row
System.out.println("Inserting new row";
customerResultSet.moveToInsertRow();
customerResultSet.updateInt("编号", 8);
customerResultSet.updateString("型号", "Price");
customerResultSet.updateString("厂家", "Jason");
customerResultSet.insertRow();
customerResultSet.moveToCurrentRow();



// display the rows in the ResultSet
System.out.println("Rows in customerResultSet");
customerResultSet.beforeFirst();
while (customerResultSet.next())
{
System.out.println("编号 = " +
customerResultSet.getInt("编号"));
System.out.println("型号 = " +
customerResultSet.getString("型号"));
System.out.println("厂家 = " +
customerResultSet.getString("厂家"));

// display the new 厂家
System.out.println("厂家 = " +
customerResultSet.getString("厂家"));

} // end of while loop

// rollback the changes made to the database
myConnection.rollback();

// close this ResultSet object using the close() method
customerResultSet.close();

// close the other JDBC objects
myStatement.close();
myConnection.close();

} // end of main()
}
...全文
208 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjmlj2010 2011-05-03
  • 打赏
  • 举报
回复
看着好晕呀
jzh196501312 2011-05-03
  • 打赏
  • 举报
回复
是否提交事物
liq1979 2011-05-03
  • 打赏
  • 举报
回复
代码肯定正确,数据库里面的数据都添加成功的,就是要显示最新添加的数据,显示不出来
lqh3672 2011-04-29
  • 打赏
  • 举报
回复
customerResultSet.insertRow();
这个实现在哪?
蛋黄车 2011-04-29
  • 打赏
  • 举报
回复

System.out.println("Inserting new row";
customerResultSet.moveToInsertRow();
customerResultSet.updateInt("编号", 8);
customerResultSet.updateString("型号", "Price");
customerResultSet.updateString("厂家", "Jason");
customerResultSet.insertRow();
customerResultSet.moveToCurrentRow();


你确定你这些方法的功能都没有问题?
ak47zhoujun123 2011-04-28
  • 打赏
  • 举报
回复
是否是因为事物的隔离级别造成的啊?

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧