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

[复制链接]
查看11 | 回复2 | 2009-9-27 10:21:22 | 显示全部楼层 |阅读模式
别的例如更新、删除都能显示出来,怎么插入新行(如下,插入编号为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(
"jdbc

racle:thin:@zyj:1521

radb",
"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&quot

;
// update row #2's first name and dob

System.out.println("Updating the 型号 row #2&quot

;

customerResultSet.absolute(2);

String new型号 = "Greg";

customerResultSet.updateString("型号", new型号);
customerResultSet.updateRow();

// display the new first name and dob
System.out.println("型号 = " + customerResultSet.getString("型号&quot

);
// delete row #5
System.out.println("Deleting row #5&quot

;
customerResultSet.absolute(5);
customerResultSet.deleteRow();
// insert a new row
System.out.println("Inserting new row&quot

;
customerResultSet.moveToInsertRow();
customerResultSet.updateInt("编号", 8);
customerResultSet.updateString("型号", "Price&quot

;
customerResultSet.updateString("厂家", "Jason&quot

;
customerResultSet.insertRow();
customerResultSet.moveToCurrentRow();

// display the rows in the ResultSet
System.out.println("Rows in customerResultSet&quot

;
customerResultSet.beforeFirst();
while (customerResultSet.next())
{
System.out.println("编号 = " +
customerResultSet.getInt("编号&quot

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

);
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()
}
回复

使用道具 举报

千问 | 2009-9-27 10:21:22 | 显示全部楼层
在线急等阿!!!!!!!!!!!!!
回复

使用道具 举报

千问 | 2009-9-27 10:21:22 | 显示全部楼层
你都设了那么多println,到哪出错呢?你是采用自动编号,还是其它类型字段?如果是自动编号,可能8早已经用过,而你仍不知道,除非你修改sequence,我不知道你用没用它。还有你的字段名字是中文吗?检查你的sql语句!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行