Failing to delete, edit from resultset
Please help me gurus, I am failing to insert and delete resultset data from ms access database. Invalid cursor state is given when I try to run delete button.
class Application
{ public static void main(String argv[])
{ Application dummy = new Application();
//Instance variables
private GUI gui;
import javax.swing.table.*;
import java.sql.*;
import java.util.*;
import java.lang.Exception;
import javax.swing.*;
class Model extends AbstractTableModel
//Variables/constants for model
private Application application;
Connection con;
Statement stmt;
//PreparedStatement pstmt;
ResultSet rs;
ResultSetMetaData rmd;
List rows = new ArrayList();
List columnNames = new ArrayList();
List dummy;
//Constructor
public Model(Application a)
{ application = a;
//public Model()
{ try
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(ClassNotFoundException e){System.out.println(e.getMessage());}
try
{ con = DriverManager.getConnection("jdbc:odbc:jdbcExample");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM birthdays ");
rmd = rs.getMetaData();
for (int i = 1; i <= rmd.getColumnCount();i++)
{ columnNames.add((String)rmd.getColumnName(i));
while(rs.next())
{ List cols = new ArrayList();
for(int col = 1; col <= columnNames.size(); col++)
{ cols.add(rs.getString(col));
rows.add(cols);
catch(SQLException e){System.out.println(e);}
//public instance methods for AbstractTableModel
public int getRowCount()
{ return rows.size();
public int getColumnCount()
{ dummy = (List)rows.get(0);
return dummy.size();
public Object getValueAt(int row, int col)
{ dummy = (List)rows.get(row);
return dummy.get(col);
public String getColumnName(int col)
{ return (String)columnNames.get(col);
public void newPerson() {
//Connection con = DriverManager.getConnection
try {
ResultSet rs = stmt.executeQuery
("SELECT * FROM birthdays WHERE familyName LIKE '%ro%' ");
while (rs.next())
{ String entry = rs.getString("givenName") +
rs.getString("familyName") +
rs.getString("birthday");
} catch( SQLException se ) { System.out.println( se ); }
public void deletePerson()
try{
rs.deleteRow() ;//throws SQLException;
catch( SQLException se ) { System.out.println( se ); }
Application dummy= new Application();
public void addText(int column,int row){
public void givenNameSort(){
try {
ResultSet rs = stmt.executeQuery
("SELECT givenName FROM birthdays");
catch( SQLException se ) { System.out.println( se ); }
public void lastNameSort(){
try {
ResultSet rs = stmt.executeQuery
("SELECT * FROM birthdays order by givenName");
catch( SQLException se ) { System.out.println( se ); }
public void dateOfBirthSort(){
try {
ResultSet rs = stmt.executeQuery
("SELECT * FROM birthdays WHERE familyName order by to_date(givenname,'MMYY' ");
catch( SQLException se ) { System.out.println( se ); }
public void saveChanges(){
private Model model;
// Constructor
public Application()
model = new Model(this);
gui = new GUI(this);
//Interface methods
public void newPerson()
{ model.newPerson();
public void deletePerson()
{ model.deletePerson();
public void editPerson(int column,int row)
{ model.addText(column,row);
public void givenNameSort()
{ model.givenNameSort();
public void lastNameSort()
{ model.lastNameSort();
public Model getModel() {
return model;
public void dateOfBirthSort()
{ model.dateOfBirthSort();
public void saveChanges()
{ model.saveChanges();
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class GUI
//Instance variables
private Application application;
private Model model;
//GUI components
private JButton helpButton = new JButton("Help");
private JButton newPersonButton = new JButton("New Person");
private JButton deletePersonButton = new JButton("Delete Person");
private JButton editPersonButton = new JButton("Edit Person");
private JButton givenNameSortButton = new JButton("Sort Givename");
private JButton lastNameSortButton = new JButton("Sort Lastname");
private JButton dateOfBirthSortButton = new JButton("Sort MoB");
private JButton saveChangesButton = new JButton("Save Changes");
private JTextField givenNameTF = new JTextField(12);
private JTextField lastNameTF = new JTextField(6);
private JTextField addressTF = new JTextField(20);
private JLabel wordCountLabel = new JLabel("Word count: 0");
//private JTextArea wordList = new JTextArea(
//private JTable dbTable = new JTable(Model());
private JTable dbTable;
//Panels, Panes and Boxes
private Box mainBox = new Box(BoxLayout.X_AXIS);
private Box controlBox = new Box(BoxLayout.Y_AXIS);
//private Panel inputBox = new Panel();
//private JScrollPane scrollingWordList; // to make wordList scroll
private JScrollPane scrollTable;
//Window.
private JFrame frame = new JFrame("JTable and TableModel");
private Container pane = frame.getContentPane();
//Constructor
public GUI( Application a)
{ this.application = a;
dbTable = new JTable( application.getModel() );
scrollTable = new JScrollPane(dbTable,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
pane.add(scrollTable);
// pane.add(inputBox);
controlBox.add(new JLabel(" "));
//inputBox.setLayout(new GridLayout(4, 2));
controlBox.add(helpButton);
controlBox.add(new JLabel(" "));
controlBox.add(newPersonButton);
controlBox.add(deletePersonButton);
controlBox.add(new JLabel(" "));
controlBox.add(editPersonButton);
controlBox.add(new JLabel(" "));
// controlBox.add(wordCountLabel);
controlBox.add(new JLabel(" "));
controlBox.add(givenNameSortButton);
controlBox.add(lastNameSortButton);
controlBox.add(dateOfBirthSortButton);
controlBox.add(new JLabel(" "));
controlBox.add(saveChangesButton);
controlBox.add(new JLabel(" "));
// inputBox.add(givenNameTF);
// inputBox.add(lastNameTF);
// inputBox.add(addressTF);
newPersonButton.addActionListener(new NewPersonButtonListener());
frame.addWindowListener(new WindowClose());
helpButton.addActionListener(new HelpButtonListener());*/
deletePersonButton.addActionListener(new DeletePersonButtonListener());
editPersonButton.addActionListener(new EditPersonButtonListener());
givenNameSortButton.addActionListener(new GivenNameSortButtonListener());
lastNameSortButton.addActionListener(new LastNameSortButtonListener());
dateOfBirthSortButton.addActionListener(new DateOfBirthSortButtonListener());
saveChangesButton.addActionListener(new SaveChangesButtonListener());
mainBox.add(controlBox);
mainBox.add(scrollTable);
// mainBox.add(inputBox);
pane.add(mainBox);
frame.addWindowListener(new FrameListener());
frame.setLocation(100, 100);
frame.setSize(300, 150);
frame.setResizable(true);
frame.setVisible(true);
frame.pack();
//Instance methods
//Listeners
class FrameListener extends WindowAdapter
{ public void windowClosing(WindowEvent evt)
{ System.exit(0);
class NewPersonButtonListener implements ActionListener
{ public void actionPerformed(ActionEvent evt)
{ application.newPerson();
class DeletePersonButtonListener implements ActionListener
{ public void actionPerformed(ActionEvent evt)
{ application.deletePerson();
class EditPersonButtonListener implements ActionListener
{ public void actionPerformed(ActionEvent evt)
{ application.editPerson(1,1);
class GivenNameSortButtonListener implements ActionListener
{ public void actionPerformed(ActionEvent evt)
{ application.givenNameSort();
class LastNameSortButtonListener implements ActionListener
{ public void actionPerformed(ActionEvent evt)
{ application.lastNameSort();
class DateOfBirthSortButtonListener implements ActionListener
{ public void actionPerformed(ActionEvent evt)
{ application.dateOfBirthSort();
class SaveChangesButtonListener implements ActionListener
{ public void actionPerformed(ActionEvent evt)
{ application.saveChanges();
}
My observations:
* I cannot see your resultset being declared as updatable anywhere.
* You should print out the stack trace while developing an application. It is usually more informative than just printing the exception message.
* Your JDBC resources are not being handled properly.
The first observation pertains to the problem at hand, I suppose.
Similar Messages
-
Disable Delete/Edit from Browse form?
Hi,
How could i remove or disable Delete/Edit/New from Wizard created jsp Browse form?
ThanksYou should be able to edit the DataTableComponent.jsp file and remove them from there.
You could also just remove the DataTable tag and build your own table. You should only have to use the RowsetIterate and Row tags to traverse the ds. Then use the showValue/renderValue to display the attributes. -
SQL Server 2012 Developer Edition will not install. Setup files don't even get copied completely. Win 8.1. ACT instance is loaded & can't be deleted. From log file: Error: Action "PreMsiTimingConfigAction" failed during execution.
Hello,
I am glad it worked.
Thank you for visiting MSDN forums!
Regards,
Alberto Morillo
SQLCoffee.com -
I am trying to delete pages from a PDF file. I opened the bookmarks in the PDF file, selected the pages to delete and choose Edit > Delete. The selected pages are not deleted. Note: I have to open the file using a passport provided by an external party.
Resolved
-
On my iPhone 5, upgraded to iOS 7, the lists in Reminders are impossible to delete. When I press Edit button in the right corner of the app, the button Delete list is supposed to be at the bottom, but it's empty there, the deal is I could delete some of the lists, but most of them I can't. I tried delete iCloud account from iPhone, but they are still there, and still no Delete button. In the Browser I don't see those lists, so cannot delete them from the Browser as well. Could you help me?
Read on another thread here that you now swipe in the opposite direction. Try swiping right to left.
-
I want to take remote access from an iTunes library off of my iPad ...when I hit edit from the remote app it pulls that library up ..if I delete it I just want to make sure that I'm not remotely wiping out the library, just access to it from my iPad ?
Call the apple store you got it from and ask them. Sometimes in the past they've extended the 'no questions asked return' but only Apple can tell you for sure.
-
I need to make space on my Mac. If I copy a folder from iPhoto on to a hard drive, then delete it from iphoto then import it again, does it retain all my editing? It does not seem to retain Faces info and I have spent hours and days naming people
There is no way to export Faces information.
I'm not sure why you would do this:
If I copy a folder from iPhoto on to a hard drive, then delete it from iphoto then import it again,
If space is an issue then move the whole Library to an external drive:
Make sure the drive is formatted Mac OS Extended (Journaled)
1. Quit iPhoto
2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
Regards
TD -
When I edit and/or delete photos from an album in iPhoto is there a way to make that what happens in the folder in finder? I am new to Mac. I've updated the operating system and iPhoto.
If your iPhoto Advanced preference pane is setup like this
all photos you import into the library are COPIED into the library. Thus those photos in the folders outside of iPhoto are redundant and can be deleted to save space on your hard drive. There no need to keep those copies in the folders.
If you do have your advance preferences set as shown above you can access your photos for use outside of iPhoto according to the following User Tip by Terence Devlin which is the best treatise on how to access photos (for use outside of iPhoto): How to Access Files in iPhoto. Otherwise you access your photos from within iPhoto. -
How can I edit or delete music from itunes match?
How can I edit or delete music from itunes match?
Hi,
If you activate match on your new laptop, you will have access to all music that you matched or uploaded. You have the option to retain the music by downloading to your computer. If you delete music, it will delete from cloud.
Jim -
Using digital editions 2.0, I cannot transfer books downloaded to digital editions from the library to my nook. I get an error message: failed to write destination file. At first, this happened once in a while but now every time. Help!!!
Modern kobo books should just use regular Adobe DRM and be readable on compatible ereaders that are authorized to the correct Adobe ID.
I understand older kobo book had different DRM: but I wouldn't expect those to
When Adobe DRM book information say 'no copying', that generally means no copying outside those Adobe DRM limitations.
You should be able to copy within the restrictions. You can double-check that with the sellers (Kobo).
Just double-checking
the pocket book is Adobe DRM compatible?
that you have authorized your pocket book with your current Adobe ID?
menu/Help/Authorize Device when plugged into ADE: Library/Authorize Device if using the older more reliable ADE 1.7.2
If the pocket book is already authorized but to a different ID, you will need to deauthorize it first, ctrl-shift-E to ADE with device plugged in (or cmd-shift-E on Mac).
Be aware that will lose the ability to read DRM books authorized with the previous ID. -
How can I delete plugins from the "edit with" menu?
I recently downloaded severals demos and trial versions of numerous softwares and plugins. They have recently expired and I'm wondering how I can delete them from the "edit with" menu. I have so many I forget which are licenced and which are trials that have expired. Please help.
Mark W../Library/Application Support/Aperture/Plug-Ins or
/Library/Application Support/Aperture/Plug-Ins
I just delete the folder of the plugin I want to get rid of. -
After upgrading to OS 8 on my iphone 5, suddenly all my contacts had Facetime capabilities. I only want to FT with a few people Unwanted FT calls now ring on both my iphone and ipad. I tried to edit and delete FT capabilities in both Contacts and Facetime icon, but there is no field to delete for this. How do I delete Factime from my contacts list? thanks for any help with this.
Hi Ingo 2711,
Thank you for your suggestion. I backup on itunes. I went to itunes, deleted syncing my contacts, then re-synced them. But the Facetime capability option continues to be there on most (not all, for some curious reason) of my contacts. I am not sure I posed my question correctly. I want to be able to FT with my family, so don't want to delete the FT capability totally from my iphone and ipad. But I don't want all these other iphone calls from various contacts to ring on my ipad as FT calls. I want a way to select with whom I have FT capabilities. Any further suggestions? Thanks much, trekpal -
Need to delete around 52000 BDC edits from SM35 in our Prodction system
Hi Guys,
I have been asked to delete around 52000 BDC edits from SM35 in our Prodction system. If i try to do by select all and then perform delte,I recieve a Time out Dump.
Since it is Production, i cannot code a Zprogram or run a session to delte automatically.
Is there a sap program avaiable that can delate this BDC via a background job?Hello,
By BDC edits, if you mean BDC sessions, you can process them in background using program RSBDCSUB.
Thanks,
Venu -
I want to delete some songs from iTunes but no delete button appears when i right click or when i try to delete it from edit. what can i do?
If the songs are downloaded into your iTunes library (i.e. they don't have the cloud icon against them) then you should be able to delete them by selecting them and pressing the delete button on your keyboard.
If they do have the cloud icon then they are in the cloud - you can turn off the showing of all icloud music via the 'Show iTunes in the Cloud Purchases' on the Store tab in iTunes > Preferences (command-comma), or you can hide individual tracks and/or albums so that they don't show in the cloud : iTunes Store: Hiding and unhiding purchases. -
After accepting meeting invitations I cannot delete them from calendar. Edit function does not appear.
settings - icloud - calendar - ON
Maybe you are looking for
-
Hi ! How I can set payment term for Customer with condition Payment on the fifth (5) of next month and use baseline date default with Document date ? Help me please.
-
I have two computers - iMac and PC. What is the EARLIEST version of Acrobat I can run on each system. I am running 10.9.2 on iMac and Windows 8 on PC. Thanks.
-
How to resize a text sprite?
This code follow can change a shape or picture sprite's dimension: vRect = mySprite.rect vRect.left = vRect.left - 5 vRect.right = vRect.right + 5 mySprite.rect = vRect But when this code is used to a text(or field) sprite, it doesn't work! Why? How
-
Oracle for Windows Server 2003 - Download file
Hi, I download Oracle9i Database Release 2 Enterprise/Standard/Personal/Client Edition for Windows Server 2003 (32-bit) from OTN(file 9203WIN2K3.zip), but it doesn't have any setup file on the extracted files. I think that file 9203WIN2K3.zip is not
-
Interpretations of 802.11 counters report on WCS
Dear Sir, My customer recently deployed WLCs and WCS in their environment. However, recently they experienced slow performance. To futher finding out the root cause, I generated the 802.11 counters report from the WCS and noticed the following parame