Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    the above sscce is out of this code.. please don't mind my posting this code.(not being sscce)

    Java Code:
    package retail_manager;
    
    /**
     *
     * @author Er. Shivam Kapoor
     */
    import java.sql.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class Q_RateRecordBook extends javax.swing.JFrame implements TableModelListener {
    
        //<editor-fold defaultstate="collapsed" desc="declaration of variables">
        protected int initial_row_count = 0;
        protected static Toolkit toolkit = Toolkit.getDefaultToolkit();
        String data[][] = {};
        String col[] = {"DESCRIPTION", "RATES/KG"};
        DefaultTableModel model = new DefaultTableModel(data, col);
        KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        KeyEventDispatcher ked;
        protected boolean flag = false;
        //</editor-fold>
    
        /** Creates new form RateRecordBook00 */
        public Q_RateRecordBook() {
            initComponents();
    
            ked = new KeyEventDispatcher() {
    
                @Override
                public boolean dispatchKeyEvent(KeyEvent e) {
                    if (e.getID() == KeyEvent.KEY_PRESSED) {
                        if (e.getKeyCode() == 27) {
                            manager.removeKeyEventDispatcher(ked);
    
                            GUIform_LOGIN.Gf01.setBounds(Global_Parameters.window_x, Global_Parameters.window_y, Global_Parameters.window_width, Global_Parameters.window_height);
                            GUIform_LOGIN.Gf01.setVisible(true);
                            dispose();
                        }
                    }
                    return false;
                }
            };
            manager.addKeyEventDispatcher(ked);
    
            jScrollPane1.getViewport().setBackground(Color.white);
            jTable1.setAutoCreateRowSorter(true);
    
            jTable1.setRowHeight(20);
            jTable1.setFont(new java.awt.Font("Times New Roman", 0, 14));
            jTable1.getModel().addTableModelListener(this);
    
            addComponentListener(new ComponentAdapter() {
    
                @Override
                public void componentResized(ComponentEvent e) {
                    Dimension window_Size = GUIform_PRIVILEGEMODE.q_rrb.getSize();
                    Global_Parameters.window_width = window_Size.width;
                    Global_Parameters.window_height = window_Size.height;
                    Global_Parameters.window_x = GUIform_PRIVILEGEMODE.q_rrb.getBounds().x;
                    Global_Parameters.window_y = GUIform_PRIVILEGEMODE.q_rrb.getBounds().y;
                }
            });
            Connection connection = null;
            Statement statement = null;
            flag = false;
            try {
                connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Oracle9i", "rms", "stephen00.rms");
                statement = connection.createStatement();
                ResultSet resultSet00 = statement.executeQuery("select * from rms_ratestore order by description");
    
                while (resultSet00.next()) {
                    Object[] rowData = {resultSet00.getObject(1), resultSet00.getObject(2)};
                    model.addRow(rowData);
                }
            } catch (SQLException sqlException) {
                sqlException.printStackTrace();
            } finally {
                try {
                    statement.close();
                    connection.close();
                    flag = true;
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }
        }
    
        public void tableChanged(TableModelEvent e) {
            if (flag) {
                
                int row = e.getFirstRow();
                int column = e.getColumn();
                TableModel _model = (TableModel) e.getSource();
                Object _data = _model.getValueAt(row, column);
                if (_data != null) {
                    Connection connection = null;
                    Statement statement = null;
                    PreparedStatement preparedStatement = null;
                    ResultSet rSet = null;
                    try {
                        connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Oracle9i", "rms", "stephen00.rms");
                        statement = connection.createStatement();
                        rSet = statement.executeQuery("select * from rms_ratestore order by description");
    
                        rSet.next();
                        int k = rSet.getRow() + row;
                        while (rSet.getRow() != k) {
                            rSet.next();
                        }
    
                        if (column == 0) {
                            preparedStatement = connection.prepareStatement("update rms_ratestore set description = ? where description = ?");
                            preparedStatement.setString(1, _data.toString());
                            preparedStatement.setString(2, rSet.getObject(1).toString());
                            preparedStatement.executeUpdate();
                        } else if (column == 1) {
                            [COLOR="RoyalBlue"]try {
                                preparedStatement = connection.prepareStatement("update rms_ratestore set ratesperkg = ? where description = ?");
                                preparedStatement.setString(1, _data.toString());
                                float f = Float.parseFloat(_data.toString());
                                preparedStatement.setString(2, rSet.getObject(1).toString());
                            } catch (NumberFormatException ne) {[/COLOR]
    [COLOR="Red"]_model.setValueAt(rSet.getObject(2).toString(), row, column);[/COLOR]                            
                                [COLOR="RoyalBlue"]JOptionPane.showMessageDialog(null, "Invalid number format", "", JOptionPane.ERROR_MESSAGE);
                            }[/COLOR]
                            preparedStatement.executeUpdate();
                        }
                    } catch (SQLException sqlException) {
                        sqlException.printStackTrace();
                    } finally {
                        try {
                            rSet.close();
                            statement.close();
                            preparedStatement.close();
                            connection.close();
                        } catch (Exception exception) {
                            exception.printStackTrace();
                        }
                    }
    
                } else {
                    JOptionPane.showMessageDialog(null, "Null entries are not allowed !", "", JOptionPane.INFORMATION_MESSAGE);
                }
            }
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable() {
    
                boolean[] canEdit = new boolean[]{
                    true, true
                };
    
                @Override
                public boolean isCellEditable(int rowIndex, int colIndex) {
                    return canEdit[colIndex];
                }
            };
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setBackground(new java.awt.Color(255, 255, 255));
            setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    
            jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
            jScrollPane1.setFont(new java.awt.Font("Times New Roman", 0, 11));
    
            jTable1.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
            jTable1.setModel(model);
            jTable1.setRowHeight(20);
            jScrollPane1.setViewportView(jTable1);
    
            getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
    
            pack();
        }// </editor-fold>                        
        // Variables declaration - do not modify                     
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        // End of variables declaration                   
    }
    Last edited by Stephen Douglas; 07-06-2010 at 08:43 AM.
    The Quieter you become the more you are able to hear !

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    java.sql.SQLException: ORA-00020: maximum number of processes (150) exceeded
    How do you create that number of processes? How does that relate to the SSCCE that you created?

  3. #23
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    How do you create that number of processes
    i don't know.. how such number of processes are created.. all i know is that the statement in red in the code above is responsible for it...

    i have discussed the issue in my post#16.. Fubarable asked me to make a sscce out of the code above.. where i highlighted the very statemnet in red..

    hope you could help. thnx.
    The Quieter you become the more you are able to hear !

  4. #24
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm no database expert, not even a novice, but your exception is an SQLException which means that there is a problem with your database or probably how you're using it. Perhaps you have too many connections open that are not being closed, I don't know. I do see that you do a bunch of database stuff from within your table model listener, and that you add the listener and then add (many?) rows to your JTable, and perhaps that may have something to do with it. Hopefully a database-savvy person will come along and will be able to help you out here. Much luck!

  5. #25
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm no database expert, not even a novice, but your exception is an SQLException which means that there is a problem with your database or probably how you're using it. Perhaps you have too many connections or other database resources open that are not being closed, I don't know. I do see that you do a bunch of database stuff from within your table model listener, and that you add the listener and then add (many?) rows to your JTable, and perhaps that may have something to do with it. Hopefully a database-savvy person will come along and will be able to help you out here. Much luck!
    Last edited by Fubarable; 07-06-2010 at 02:06 AM.

  6. #26
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    I fixed the bug :) in code above in blue.. by using an alternative snippet of code to it..

    Java Code:
    try {
                                float f = Float.parseFloat(_data.toString());
                            } catch (NumberFormatException ne) {
                                _model.setValueAt(rSet.getObject(2).toString(), row, column);
                                JOptionPane.showMessageDialog(null, "Invalid number format", "", JOptionPane.ERROR_MESSAGE);
                            }
                                preparedStatement = connection.prepareStatement("update rms_ratestore set ratesperkg = ? where description = ?");
                                preparedStatement.setString(1, _data.toString());
                                preparedStatement.setString(2, rSet.getObject(1).toString());
    
                                preparedStatement.executeUpdate();
                        }
    but I still haven't figured out the cause of the problem..please suggest.:(
    The Quieter you become the more you are able to hear !

  7. #27
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    For starters I suspect it all comes down to tying your db code so closely to your Swing code. That is incredibly messy.

    Also, doing the parse in the middle of building a statement makes no sense, because then you apparently execute that statement. Except you can't be otherwise you'd get a different exception regarding not having all the parameters assigned. So I'm guessing (and without debugging through it all it is a guess) that the JOption is moving the processing into some sort of loop?

    Anyway, your logic seems a bit all over the place. Create a db layer, that is a simple Data Access Object (DAO) that does all the database work for you, which will have a handful of methods. One for getting all the rows in rms_ratestore, turning that into an ArrayList of RMSRateStore objects (you'll have to write that one). One for updating, which will take a the parameters needed by the PreparedStatement you have.

    Why on earth you're getting all the rows again when someone has edited a field I don't know. And then to loop through it all to find the same row number...that's a bug waiting to happen right there. Never rely on row number...always use a primary key.

    Similarly aren't you supposed to be checking the users input? Not the value already in the table?

    Sorry for the mass of questions, but this code really needs them.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 1
    Last Post: 07-14-2009, 07:04 PM
  2. Replies: 2
    Last Post: 04-01-2009, 08:37 AM
  3. java floating point comparison
    By sardare in forum Advanced Java
    Replies: 6
    Last Post: 03-03-2009, 04:11 PM
  4. number of floating point
    By mohammad8065 in forum Advanced Java
    Replies: 5
    Last Post: 12-28-2008, 09:41 AM
  5. Floating point values in SWT Spinner
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-07-2008, 04:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •