使用netbeans将数据插入到oracle表中

时间:2013-12-12 01:24:27

标签: sql oracle netbeans

我想使用netbeans文本字段将数据插入到我的oracle表中,并且此代码存在问题。当这个屏幕执行时,它给了我一个例外:

  

java.sql.SQLException:列索引无效

请尽快帮助我。

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
    conn = javadb.ConnectDb();

    try{
        String sql = "insert into addbook (id, title, isbn, author)"
                + " values(null,'','','');";
        pst = (OraclePreparedStatement) conn.prepareStatement(sql);
        pst.setString(1, title.getText());
        pst.setString(2, isbn.getText());
        pst.setString(3, author.getText());
        rs = (OracleResultSet) pst.executeQuery();

    }catch(SQLException | HeadlessException e){
        JOptionPane.showMessageDialog(null, e);
    }
}                                        

2 个答案:

答案 0 :(得分:1)

conn = JavaDbCon.ConnecrDb();

import tkinter as tk


class GUI(tk.Frame):
    def __init__(self, master):
        self.test_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
        self.c = tk.Canvas(master, width=300, height=300)
        self.c.pack()

        for idx, elt in enumerate(self.test_list):
            row = (idx // 3 + 5) * 20
            col = (idx % 3 + 5) * 20

            self.c.create_text(row, col, text=elt)


if __name__ == '__main__':

    root = tk.Tk()
    root.title("Test")
    root.geometry("300x300")
    GUI(root)
    root.mainloop()

答案 1 :(得分:0)

这应该可行,试试这个。

   conn = javadb.ConnectDb();

        try{
            String sql = "insert into addbook (id, title, isbn, author) values(?,?,?,?)";
            pst = (OraclePreparedStatement) conn.prepareStatement(sql);

            pst.setString(1,'NULL');
            pst.setString(2, title.getText());
            pst.setString(3, isbn.getText());
            pst.setString(4, author.getText());
            rs = (OracleResultSet) pst.executeUpdate(sql);

        }catch(SQLException | HeadlessException e){
        JOptionPane.showMessageDialog(null, e);
        }
    }