简体   繁体   中英

how to store values in jtable without a database in java

private void bt_commit1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        DBUtil util = new DBUtil();
        try {

            Connection con = util.getConnection();
            PreparedStatement stmt = con.prepareStatement("INSERT INTO dbo.bk_det(rm_id,bk_name,bk_branch) VALUES (?,?,?)");
            String rm = (tf_rm_id.getText().trim() == null || tf_rm_id.getText().equals("")) ? "0" : tf_rm_id.getText();
            String a = (txtbkname.getText().trim() == null || txtbkname.getText().equals("")) ? "UNKNOWN" : txtbkname.getText();
            String b = (txtbkbranch.getText().trim() == null || txtbkbranch.getText().equals("")) ? "UNKNOWN" : txtbkbranch.getText();

            stmt.setString(1, ""+(rm));
            stmt.setString(2, ""+(a));
            stmt.setString(3, ""+(b));

            stmt.execute();
            JOptionPane.showMessageDialog(null, "COMMITED SUCCESSFULLY!");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
            Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
        }

i actually want to store the values in table without using the sql database. here i am using the sql statements to connect to my data base but i want to store the values from my java gui in netbeans to jtabel without a database

Since JTable is a GUI component, you cannot store values in it. It only renders them. Once each reference to that component is lost, there's no way you can hold your information.

On the other hand, Netbeans it's just an IDE, like eclipse or others. You can draw a JTable components on its editor and launch your application as well, but it doesn't accomplish storing purposes.

Nonetheless, if you're looking for a storing mechanism other than a database like MySQL, PostgreSQL or Oracle, you could use MySQLite or XML files, just to name some.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM