Ich will das conn weitergeben ( für ResultSet und Close.conn ), aber irgendwie funzt es nicht?!?!
Code:
package graphics;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.net.*;
import work.*;
public class Befehl extends JFrame{
private static JTextArea ausgabe = new JTextArea();
private JTextField eins = new JTextField();
//private JTextField zwei = new JTextField();
//private JTextField drei = new JTextField();
public static void Tex(String text){
Befehl.ausgabe.append("\n"+text);}
public Befehl(){
super("Befehlseingabe");
JPanel pan = new JPanel();
pan.setLayout(new GridBagLayout());
pan.setBackground(Color.white);
JLabel lab = new JLabel();
lab.setOpaque(true);
lab.setBackground(Color.blue);
lab.setForeground(Color.red);
lab.setFont(new Font("Helvetica", Font.BOLD, 24));
lab.setText("Auswahl");
pan.add(lab, new GridBagConstraints(0,0,1,1,0.0,0.5,
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,0,0), 1, 1));
JLabel lab2 = new JLabel();
lab2.setOpaque(true);
lab2.setBackground(Color.blue);
lab2.setForeground(Color.black);
lab2.setFont(new Font("Helvetica", Font.PLAIN, 21));
lab2.setText("Bitte wählen Sie aus dem Menü den entsprechenden Programmpunkt");
pan.add(lab2, new GridBagConstraints(0,1,1,0,0.0,0.5,
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,0,0),1,1));
JPanel pan2 = new JPanel();
pan2.setLayout(new GridBagLayout());
pan2.setBackground(Color.blue);
/*JLabel lab3 = new JLabel();
lab3.setOpaque(true);
lab3.setFont(new Font("Helvetica", Font.PLAIN, 18));
//lab3.setText("Update-, Insert-, Delete-Befehle: ");
pan2.add(lab3, new GridBagConstraints(0,1,1,1,0.0,0.5,
GridBagConstraints.CENTER,GridBagConstraints.NONE, new Insets(0,0,0,0),1,1));*/
JButton b1 = new JButton();
b1.setText("Abfrage");
b1.setBackground(Color.green);
b1.addActionListener(AL2);
pan2.add(b1, new GridBagConstraints(0,0,1,1,1.0,1.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
eins.setFont(new Font("Helvetica", Font.BOLD, 18));
String tfeins = eins.getText();
pan2.add(eins, new GridBagConstraints(1,0,1,1,1.0,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
JPanel pan3 = new JPanel();
pan3.setLayout(new GridBagLayout());
ausgabe.setFont(new Font("Helvetica", Font.BOLD, 12));
JScrollPane scroll = new JScrollPane(ausgabe);
pan3.add(scroll, new GridBagConstraints(0,0,1,1,1.0,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
this.getContentPane().setLayout(new GridBagLayout());
this.getContentPane().add(pan, new GridBagConstraints(0,0,1,1,1.0,1.0,
GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
this.getContentPane().add(pan2, new GridBagConstraints(0,1,1,1,1.0,1.0,
GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
this.getContentPane().add(pan3, new GridBagConstraints(0,2,1,1,1.0,1.0,
GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
}
ActionListener AL2 = new ActionListener(){
public void actionPerformed(ActionEvent e){
Abfrage V = new Abfrage(eins.getText(), Connection conn)));}};
}
public class Abfrage{
public Abfrage(String tfeins, Connection conn){
Statement stmt = null;
ResultSet res = null;
Connn.Text("Verarbeitung beginnt");
try{
stmt = conn.createStatement();
}
catch(SQLException e){
Befehl.Tex("Fehler beim Ausführen der Abrage"+e);
};
try{
if ( stmt.execute(tfeins)){
res = stmt.getResultSet();
//show_result(res);
res.close();
}
else{
graphics.Befehl.Tex("Abfrage ausgeführt");
graphics.Befehl.Tex("\r\nAnzahl Datensätze: "+ stmt.getUpdateCount());
}
}
catch (SQLException e){
Befehl.Tex("Fehler beim Ausführen der Abfrage: "+ e);
}
try{
stmt.cancel();
stmt.close();
}
catch (SQLException e){
graphics.Befehl.Tex("Fehler beim Ausführen der Abfrage" +e);
}
}
}
ActionListener CL = new ActionListener(){
public void actionPerformed(ActionEvent e){
//conn.close();
meld.append("\n" + "Verbindung beendet");