JDBC-ResultSet.getString Vor/Nach Start/Ende der Ergebnismenge Ausnahme

Ich habe schon viel über die Suche zu diesem Thema über Google, aber ich habe noch jemanden zu finden, mit getString() in der Weise, dass ich es mit so ich nicht in der Lage das Problem zu beheben, in der normalen Wege, die vorgeschlagen werden.

Was ich versuche zu tun ist, erhalten alle Informationen aus der Datenbank und verwenden Sie zum Auffüllen eine Tabelle Modell im Programm. Ich tun, damit durch den Erhalt der Daten mit getString, und platzieren Sie es in ein String [] - Objekt. Hier ist mein MySQLConnection Klasse:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class MySQLConnect
{
    public MySQLConnect()
    {
        connect = null;
        statement = null;
        rSet = null;    
    }

    public void Connect(String dbase, String uname, String pword)
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver");

            connect = DriverManager.getConnection("jdbc:mysql://localhost/" + dbase , uname, pword);
            JOptionPane.showMessageDialog(null, "Connection successful.  Please retry your submission." , "Information", JOptionPane.INFORMATION_MESSAGE);          
        }

        catch (Exception e)
        {
            JOptionPane.showMessageDialog(null, e , "SQL Error", JOptionPane.ERROR_MESSAGE);
        }       
    }

    public void addDonor(int did, String dname, String dcname, int damount, DefaultTableModel model)
    {
        try
        {
            statement = connect.createStatement();

            statement.execute("Insert Into prg421_w5.donors Values ("+ did + ",'" + dname + "','" + dcname + "'," + damount + ")");
            JOptionPane.showMessageDialog(null, "Data entry added successfully." , "Information", JOptionPane.INFORMATION_MESSAGE);
            getRSet();
            updateTable(model);
        }

        catch (Exception e)
        {
            JOptionPane.showMessageDialog(null, e , "SQL Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    public void getRSet()
    {
        try 
        {
            rSet = statement.executeQuery("Select * From donors");
        }

        catch (Exception e)
        {

        }
    }

    public void updateTable (DefaultTableModel model)
    {
        try
        {
            for (i = getRowCount(); i > 0; i--)
            {
                model.removeRow(0);
            }
        }

        catch (Exception e)
        {
            JOptionPane.showMessageDialog(null, e , "SQL Error", JOptionPane.ERROR_MESSAGE);
        }

        try
        {
            while (rSet.next())
            {
                String row[] = {rSet.getString("DonorName"),rSet.getString("DonorCharity"),((String)rSet.getString("DonationAmount"))};

                model.addRow(row);      
            }
        }

        catch (Exception e)
        {
            JOptionPane.showMessageDialog(null, e , "SQL Error", JOptionPane.ERROR_MESSAGE);
        }       
    }

    public int getRowCount()
    {
        try
        {
            rowCount = rSet.getInt(1);
        }

        catch (Exception e)
        {
            JOptionPane.showMessageDialog(null, e , "SQL Error", JOptionPane.ERROR_MESSAGE);
        }

        return rowCount;
    }   

    public Boolean isConnected()
    {
        return connect != null;
    }

    public void Close()
    {
        try
        {
          if (rSet != null)
          {
              rSet.close();
          }

          if (statement != null)
          {
              statement.close();
          }

          if (connect != null)
          {
              connect.close();
          }
        }

        catch (Exception e)
        {
            JOptionPane.showMessageDialog(null, e , "SQL Error", JOptionPane.ERROR_MESSAGE);
        }
    }


    private Connection connect;
    private Statement statement;
    private ResultSet rSet;
    private int rowCount, i;

    private static Object o = null;
}

Jedoch bin ich immer ein Dialogfeld Fehlermeldung, die besagt, diese Fehlermeldungen im Titel:

Ausnahme: Vor dem start der Ergebnismenge

Ausnahme: Nach Ende des ResultSet

Hier sind die stack-traces:

java.sql.SQLException: Vor dem start der Ergebnismenge an
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074) an
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988) an
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974) bei
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919) an
com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:854) an
com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2709) bei
MySQLConnect.getRowCount(MySQLConnect.java:100) at
MySQLConnect.updateTable(MySQLConnect.java:68) an
MySQLConnect.addDonor(MySQLConnect.java:42) at
Operationen.addDonor(Operationen.java:135) at
GUI$Event-Handler.actionPerformed(GUI.java:145) at
javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at
javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.setPressed(Unknown Source) at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Source) bei java.das awt.Komponente.processMouseEvent(Unknown Source) at
javax.swing.JComponent.processMouseEvent(Unknown Source) at
java.das awt.Komponente.processEvent(Unknown Source) at
java.das awt.Container.processEvent(Unknown Source) at
java.das awt.Komponente.dispatchEventImpl(Unknown Source) at
java.das awt.Container.dispatchEventImpl(Unknown Source) at
java.das awt.Komponente.dispatchEvent(Unknown Source) at
java.das awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at
java.das awt.LightweightDispatcher.processMouseEvent(Unknown Source) at
java.das awt.LightweightDispatcher.dispatchEvent(Unknown Source) at
java.das awt.Container.dispatchEventImpl(Unknown Source) at
java.das awt.Fenster.dispatchEventImpl(Unknown Source) at
java.das awt.Komponente.dispatchEvent(Unknown Source) at
java.das awt.EventQueue.dispatchEventImpl(Unknown Source) at
java.das awt.EventQueue.access$200(Unknown Source) at
java.das awt.EventQueue$3.run(Unknown Source) at
java.das awt.EventQueue$3.run(Unknown Source) at
java.Sicherheit.AccessController.doPrivileged(Native Method) at
java.Sicherheit.ProtectionDomain$1.doIntersectionPrivilege(Unbekannt
Source) at
java.Sicherheit.ProtectionDomain$1.doIntersectionPrivilege(Unbekannt
Source) bei java.das awt.EventQueue$4.run(Unknown Source) at
java.das awt.EventQueue$4.run(Unknown Source) at
java.Sicherheit.AccessController.doPrivileged(Native Method) at
java.Sicherheit.ProtectionDomain$1.doIntersectionPrivilege(Unbekannt
Source) bei java.das awt.EventQueue.dispatchEvent(Unknown Source) at
java.das awt.EventDispatchThread.pumpOneEventForFilters(Quelle Unbekannt)
bei java.das awt.EventDispatchThread.pumpEventsForFilter(Quelle Unbekannt)
bei java.das awt.EventDispatchThread.pumpEventsForHierarchy(Unbekannt
Source) bei java.das awt.EventDispatchThread.pumpEvents(Unknown Source)
bei java.das awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.das awt.EventDispatchThread.run(Unknown Source)

java.sql.SQLException: Nach Ende der Ergebnismenge an
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074) an
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988) an
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974) bei
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919) an
com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:854) an
com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2709) bei
MySQLConnect.getRowCount(MySQLConnect.java:100) at
MySQLConnect.updateTable(MySQLConnect.java:68) an
Operationen.updateTable(Operationen.java:164) at
GUI$Event-Handler.actionPerformed(GUI.java:148) at
javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at
javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.setPressed(Unknown Source) at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Source) bei java.das awt.Komponente.processMouseEvent(Unknown Source) at
javax.swing.JComponent.processMouseEvent(Unknown Source) at
java.das awt.Komponente.processEvent(Unknown Source) at
java.das awt.Container.processEvent(Unknown Source) at
java.das awt.Komponente.dispatchEventImpl(Unknown Source) at
java.das awt.Container.dispatchEventImpl(Unknown Source) at
java.das awt.Komponente.dispatchEvent(Unknown Source) at
java.das awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at
java.das awt.LightweightDispatcher.processMouseEvent(Unknown Source) at
java.das awt.LightweightDispatcher.dispatchEvent(Unknown Source) at
java.das awt.Container.dispatchEventImpl(Unknown Source) at
java.das awt.Fenster.dispatchEventImpl(Unknown Source) at
java.das awt.Komponente.dispatchEvent(Unknown Source) at
java.das awt.EventQueue.dispatchEventImpl(Unknown Source) at
java.das awt.EventQueue.access$200(Unknown Source) at
java.das awt.EventQueue$3.run(Unknown Source) at
java.das awt.EventQueue$3.run(Unknown Source) at
java.Sicherheit.AccessController.doPrivileged(Native Method) at
java.Sicherheit.ProtectionDomain$1.doIntersectionPrivilege(Unbekannt
Source) at
java.Sicherheit.ProtectionDomain$1.doIntersectionPrivilege(Unbekannt
Source) bei java.das awt.EventQueue$4.run(Unknown Source) at
java.das awt.EventQueue$4.run(Unknown Source) at
java.Sicherheit.AccessController.doPrivileged(Native Method) at
java.Sicherheit.ProtectionDomain$1.doIntersectionPrivilege(Unbekannt
Source) bei java.das awt.EventQueue.dispatchEvent(Unknown Source) at
java.das awt.EventDispatchThread.pumpOneEventForFilters(Quelle Unbekannt)
bei java.das awt.EventDispatchThread.pumpEventsForFilter(Quelle Unbekannt)
bei java.das awt.EventDispatchThread.pumpEventsForHierarchy(Unbekannt
Source) bei java.das awt.EventDispatchThread.pumpEvents(Unknown Source)
bei java.das awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.das awt.EventDispatchThread.run(Unknown Source)

Die Fehler sind tatsächlich generiert sich aus der rSet.getInt(1); in meinem getRowCount () - Methode.

Sind die Daten noch Hinzugefügt und alles funktioniert korrekt, aber es ist einfach ärgerlich zu haben, um entlassen diese Meldung von windows. Hat jemand ein paar Vorschläge?

  • können Sie bitte poste mehr code und den StackTrace zu sehen, wie der code sich verhält, und erklären Sie, welche Art von Fehler/Warnung sind Sie konfrontiert?
  • Schreiben Sie Ihre vollständige code für die Klasse.
  • Getan.
  • Schreiben Sie komplette stack-trace des Fehlers, Sie bekommen
InformationsquelleAutor Geowil | 2012-11-11
Schreibe einen Kommentar