别的例如更新、删除都能显示出来,怎么插入新行(如下,插入编号为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()
}
/// 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()
}
System.out.println("Inserting new row";
customerResultSet.moveToInsertRow();
customerResultSet.updateInt("编号", 8);
customerResultSet.updateString("型号", "Price");
customerResultSet.updateString("厂家", "Jason");
customerResultSet.insertRow();
customerResultSet.moveToCurrentRow();
你确定你这些方法的功能都没有问题?
这个实现在哪?