deleterow()ReadOnly语句错误

时间:2012-04-05 15:11:04

标签: java oracle jdbc

我正在使用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代码和坏英语而烦恼-..-'''

1 个答案:

答案 0 :(得分:3)

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