1

我正在使用 JDBC/Oracle 做我的第一个应用程序......今天我遇到了一个问题,我无法找出问题所在。

这是我的代码(某些部分)

我的全局变量:

public class Esercizio02_GestioneDB {

public Esercizio02_GestioneDB(){

}

public Connection conn = null;
public Statement s = null;
public ResultSet rs = null;
public ResultSet rs1 = null;
ResultSetMetaData rsmd = null;
ResultSetMetaData rsmd1 = null;

[...]

我的连接方法:

public void connetti(String user, String pwd) throws ClassNotFoundException, SQLException {

        //DRIVER
        Class.forName("oracle.jdbc.driver.OracleDriver");

        //URL
        String url = "jdbc:oracle:thin:@//localhost:1521/xe";

        //CONNECTION
        conn = DriverManager.getConnection(url, user, pwd);

        //AUTOCOMMIT
        conn.setAutoCommit(true);

        //STATEMENT
        s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,    ResultSet.CONCUR_UPDATABLE);         


}

所以,我有一种方法可以删除表中的一行:

private void eliminaPrenotazione() {

    try {

        String message1 = "Scegli la prenotazione da cancellare:\n\n";

        String query = "SELECT * FROM camere_prenotate";

        rs1 = s.executeQuery(query);
        rsmd1 = rs1.getMetaData();

        message1 += "INDICE ";
        for (int i=1; i<=rsmd1.getColumnCount(); i++) {
            message1 += rsmd1.getColumnName(i);
            message1 += " \t ";
        }
        message1 += "\n_______________________________\n";

        int rowIndex = 1;
        String columnType = "";
        while (rs1.next()) {    
            message1 += "["+rowIndex+"]. ";
            rowIndex++;

            for (int i=1; i<=rsmd1.getColumnCount(); i++) {

                columnType = rsmd1.getColumnTypeName(i);

                if(columnType.substring(0, 3).equalsIgnoreCase("num")) message1 += rs1.getInt(i);
                if(columnType.substring(0, 3).equalsIgnoreCase("var") || columnType.substring(0, 3).equalsIgnoreCase("dat"))
                        message1 += rs1.getString(i);

                message1 += " \t ";
            }
            message1 +="\n";
        }
        message1 +="\n";

        String scelta = JOptionPane.showInputDialog(null, message1);
        int sceltaInt = Integer.parseInt(scelta);

        rs1.absolute(sceltaInt);
        rs1.deleteRow();



    } catch (Exception e) {

        JOptionPane.showMessageDialog(null, "Errore: " + e.getMessage());
    }

}

deleteRow() 返回一个错误...它说我的 ResultSet 是只读的,但在我的声明中它被定义为

s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

那么,怎么了?

对不起noobish代码和糟糕的英语-.-'''

4

1 回答 1

4

select *使Resultset实例只读。
select COLUMNNAME使其可更新。

于 2012-04-05T15:28:39.353 回答