Code:
if (obj instanceof JButton)
{
System.out.println("Ereignis");
if (event.getActionCommand()=="suchen")
{
String eingabelaenge = textfield1.getText();
if (eingabelaenge.length() < 3)
{
JOptionPane.showMessageDialog(this,
"Minimale Eingabe: 3 Zeichen.");
}
else
{
// Suchanfrage
Sql query = new Sql();
ResultSet test = query.search(textfield1.getText());
try
{
while(test.next())
{
String surname = test.getString("Surname");
String firstname = test.getString("First Name");
String titel = test.getString("Titel");
String type = test.getString("Type");
System.out.print("Surname: "+surname+" -----First Name:----- "+firstname+
" -----Titel:----- "+titel+"----- Typ:----- "+type+"\n");
}
}
catch( Exception e )
{
e.printStackTrace();
}
}
import java.sql.*;
public class Sql
{
ResultSet rs;
public static void main(String args[])
{
}
public ResultSet search(String suche)
{
try
{
Statement stmt;
//ResultSet rs;
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/stahl";
Connection con = DriverManager.getConnection(url,"buch", "buch");
stmt = con.createStatement();
//rs = stmt.executeQuery("select * from Book B, Item I WHERE B.Itemidentity = I.Identity");
rs = stmt.executeQuery("SELECT Surname, `First Name`, Type, Titel " +
"FROM `Item_All_Author`, Author, Item, Mediatype " +
"WHERE (((`Item_All_Author`.AuthorIdentity = Author.Identity) " +
"AND (`Item_All_Author`.ItemIdentity = Item.Identity) " +
"AND (Item.MediatypeIdentity = Mediatype.Identity)) " +
"AND ((Author.Surname = '"+suche+"') OR (Author.`First Name` = '"+suche+"')))");
con.close();
}
catch( Exception e )
{
e.printStackTrace();
}
return rs;
}
}
java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.ResultSet.checkClosed(ResultSet.java:639)
at com.mysql.jdbc.ResultSet.next(ResultSet.java:6116)
at UsingLayoutManagers.actionPerformed(UsingLayoutManagers.java:330)
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)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Diese kleine Fehlermeldung wirft mir java aus wenn das Ereignis ausgelöst wird...
Passieren soll folgendes: Eingabe auslesen, Instanz der Klasse Sql erstellen, suche(); Ergebnis ausgeben.
Ab wann ist ein resultset closed?
Julius