Results 1 to 3 of 3
- 01-31-2010, 03:11 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 4
- Rep Power
- 0
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
- 02-01-2010, 09:33 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
You need to give us the stack trace and full error message.
- 03-06-2010, 01:29 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Problem with int method ..!!
By ŖàΫ ỏƒ Ңόρę in forum New To JavaReplies: 19Last Post: 01-17-2010, 09:35 PM -
recursive method problem
By melody in forum New To JavaReplies: 1Last Post: 10-29-2009, 07:15 AM -
Method problem
By Jeff6461 in forum New To JavaReplies: 1Last Post: 03-02-2009, 06:48 AM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM -
Problem with sort method
By Albert in forum Advanced JavaReplies: 2Last Post: 07-01-2007, 07:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks