Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Parse boolean from Access db

807606Apr 26 2007 — edited Apr 27 2007
Hi, I am trying to parse a boolean in from an access database and here's what happens.

1) When I populate the JTable that I'm using when the form initially loads, the table populates correctly.

2) After I edit information using JTextFields, I submit the query to update, which occurs with no issues

3) I then select all fields within the table using the SAME method as above, it throws the following error.

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String

The line of code its having trouble on is:
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
NOTE: This code is auto-generated by Netbeans and cannot be modified.

The following is my code which is used to populate the JTable:
        public void populateTable()
    {
            ResultSet newResults;
            try {
                myDatabase.loadDriver();
                newResults = myDatabase.runQuery("SELECT * FROM User","search", "null");
                
                
                int columnID = 1;
                int rowID = 0;
                
                while(newResults.next() == true)
                {
                    while(columnID <= 3)
                    {
                        if (columnID == 2)
                        {
                            String temp = newResults.getString(columnID);
                            String output = "";
                            
                            int i = 1;
                            while (i <= temp.length())
                            {
                                output = output + "*";
                                i++;
                            }
                            tblData.setValueAt(output, rowID, columnID - 1);
                            columnID++;
                        }
                        else if (columnID == 3)
                        {
                            tblData.setValueAt(newResults.getBoolean(3), rowID, columnID - 1);
                            columnID++;
                        }
                        else
                        {
                            tblData.setValueAt(newResults.getString(columnID), rowID, columnID - 1);
                            columnID++;
                        }
                        //If all six columns of a row have been filled, move to the next row
                    }
                    columnID = 1;
                    rowID++;
                }
                
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
    }
Any ideas? Thanks in advance.

Message was edited by:
bcwolfe
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 25 2007
Added on Apr 26 2007
8 comments
174 views