Results 1 to 3 of 3
  1. #1
    Aniczka is offline Member
    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0

    Default JdbcRowsetImpl execute() method problem

    Hi,I'm writing the program that allows searching property database and displaying the results.It alo all0ws deleting and updating.InitiallyI was using ResultSet for search nd display,but after deleting the record and going through results I was getting an error 'invalid cursor position', probably because it was trying to access deleted record.Now after I enter search parameters I get Null pointer exception pointing at execute() method.Here's the code:
    Java Code:
    try {
    
                //Get the locatiob entered by user
                location = jtfLocation.getText();
                //Get the price range selected by user
                price = jcbPrice.getSelectedIndex();
                priceStr = "";
    
                //Check if location was entered
                if(location.equals("")){//Location wasn't entered
                    //Display appropriate message
                    JOptionPane.showMessageDialog(null,"Enter location!","LIT Realty",JOptionPane.INFORMATION_MESSAGE);
                }
                else{//Location was entered
                    //Check which range was selected and create appropriate 'WHERE' clause
                    if (price == 0) {
                        priceStr = "SELECT street,bedrooms,bathrooms,squarefeet,description,photo,price FROM properties WHERE city LIKE '" + location + "'";
                    } else if (price == 1) {
                        priceStr = "SELECT street,bedrooms,bathrooms,squarefeet,description,photo,price FROM properties WHERE city LIKE '" + location + "' AND (price>100000 AND price<150000);";
                    } else if (price == 2) {
                        priceStr = "SELECT street,bedrooms,bathrooms,squarefeet,description,photo,price FROM properties WHERE city LIKE '" + location + "' AND (price>150000 AND price<200000);";
                    } else if (price == 3) {
                        priceStr = "SELECT street,bedrooms,bathrooms,squarefeet,description,photo,price FROM properties WHERE city LIKE '" + location + "' AND (price>200000 AND price<250000);";
                    } else if (price == 4) {
                        priceStr = "SELECT street,bedrooms,bathrooms,squarefeet,description,photo,price FROM properties WHERE city LIKE '" + location + "' AND (price>250000 AND price<350000);";
                    } else if (price == 5) {
                        priceStr = "SELECT street,bedrooms,bathrooms,squarefeet,description,photo,price FROM properties WHERE city LIKE '" + location + "' AND (price>350000 AND price<500000);";
                    } else if (price == 6) {
                        priceStr = "SELECT street,bedrooms,bathrooms,squarefeet,description,photo,price FROM properties WHERE city LIKE '" + location + "' AND price>500000;";
                    }
                    //Load the correct driver for the database
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    
                    //Create the connection object
                    //connection = DriverManager.getConnection("jdbc:odbc:Pract4", "", "");
    
                    //Create a statement object
                    //statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    
                    //Execute our query, which will lead to the return of a resultset
                    //resultSet = statement.executeQuery(priceStr);
    
                    //Move cursor to the first row
                    //resultSet.first();
    
                    rowset=new JdbcRowSetImpl();
                    rowset.setCommand(priceStr);
                    rowset.setUrl("jdbc:odbc:Pract4");
                    rowset.execute();
                    rowset.first();
    
                    if (rowset.first() == false)
                    //Check if any results were returned
                    if (rowset.first() == false) {//No results returned
                        JOptionPane.showMessageDialog(null, "There are no properties on file which match your criteria.", "LIT Realty", JOptionPane.INFORMATION_MESSAGE);
                    }
                    else {//Results returned
                        retrieveRecords();//Retrieve records from resultset
                        currentFrame.setVisible(false);//Close current frame
                        ResultFrame next = new ResultFrame();//Create the instance of frame that displays results
                        next.setVisible(true);//Dispaly the frame with results
    
                    }
                }
    
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(SearchFrame.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(SearchFrame.class.getName()).log(Level.SEVERE, null, ex);
            } 
    }
    Last edited by Fubarable; 01-31-2010 at 03:19 PM. Reason: code tags added

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    You need to give us the stack trace and full error message.

  3. #3
    Aniczka is offline Member
    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0

    Default

    sorry for not replying,was away.migrated database to mysql.rowset is not for access,i was told.thank you anyway.

Similar Threads

  1. Problem with int method ..!!
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 19
    Last Post: 01-17-2010, 09:35 PM
  2. recursive method problem
    By melody in forum New To Java
    Replies: 1
    Last Post: 10-29-2009, 07:15 AM
  3. Method problem
    By Jeff6461 in forum New To Java
    Replies: 1
    Last Post: 03-02-2009, 06:48 AM
  4. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  5. Problem with sort method
    By Albert in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 07:12 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
  •