So, das is dann ma der ganze Code inkl Fehlermeldung:
Fehlermeldung:
Ich werd mich mal währenddessen etwas schlauer machen, wie das nun mit dem Button t, das wurmt mich derzeit ziemlich...
Bin aber trotzdem über jeden Lösungsvorschlag (wie gesagt, bitte MIT beispielcode, wenn ihr grad was auf Lager habt) dankbar!
Code:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.*;
import javax.swing.event.*;
/**
*
* @Beschreibung: Kleine einfache GUI zum Verbinden mit der Pumacy Oracle-Test-DB,
* Daten auslesen und verändern mittels SQL-Befehle
*
* @version 1.0 vom 22.09.2008
* @author: Florian Adler
*/
public class Datenbank_auslesen extends JFrame implements ActionListener {
// Anfang Attribute
private String[] jComboBox1Data = {};
private JComboBox jComboBox1 = new JComboBox(jComboBox1Data);
private JTextField jTextField1 = new JTextField();
private JButton jButton1 = new JButton();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JTextArea jTextArea1 = new JTextArea("");
private JButton jButton2 = new JButton();
// Ende Attribute
public Datenbank_auslesen(String title) {
// Frame-Initialisierung
super(title);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
int frameWidth = 500;
int frameHeight = 500;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
Font f= new Font("ComicSans", Font.BOLD, 12);
jComboBox1.setFont(f);
jComboBox1.setBounds(24, 48, 210, 24);
jComboBox1.setBackground(Color.WHITE);
jComboBox1.setForeground(Color.BLACK);
jComboBox1.addItem("-------------");
jComboBox1.addItem(" 0-9 ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" A ... ");
jComboBox1.addItem("Action");
jComboBox1.addItem("Action2Systemrole");
jComboBox1.addItem("AuthenticationInstrument");
jComboBox1.addItem("AuthenticationMethod");
jComboBox1.addItem("AuthenticationMethod2Channel");
jComboBox1.addItem("Author2Document");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" B ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" C ...");
jComboBox1.addItem("Category");
jComboBox1.addItem("Category Keyword");
jComboBox1.addItem("Change Request");
jComboBox1.addItem("Channel");
jComboBox1.addItem("Commentaries");
jComboBox1.addItem("Community");
jComboBox1.addItem("CommunityTemplates");
jComboBox1.addItem("CommunityUser");
jComboBox1.addItem("CommunityUsergroup");
jComboBox1.addItem("ComminutyWorkflow");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" D ...");
jComboBox1.addItem("Document");
jComboBox1.addItem("DocumentArchive");
jComboBox1.addItem("DocumentField");
jComboBox1.addItem("DocumentFieldArchive");
jComboBox1.addItem("DocumentHistory");
jComboBox1.addItem("DocumentParticipants");
jComboBox1.addItem("DocumentRating");
jComboBox1.addItem("DocumentSignature");
jComboBox1.addItem("DocumentTypeCategory");
jComboBox1.addItem("DocumentTypeSequence");
jComboBox1.addItem("Document2Category");
jComboBox1.addItem("Document2Document");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" E ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" F ...");
jComboBox1.addItem("Favorites");
jComboBox1.addItem("FQSFDocument");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" G ...");
jComboBox1.addItem("Group2WFRole");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" H ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" I ...");
jComboBox1.addItem("IntendedReleasePeriodDate");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" J ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" K ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" L ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" M ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" N ...");
jComboBox1.addItem("News");
jComboBox1.addItem("Notification");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" O ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" P ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" Q ...");
jComboBox1.addItem("QSFDocument");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" R ...");
jComboBox1.addItem("RatingItem");
jComboBox1.addItem("RatingType");
jComboBox1.addItem("ReviewReleaseDate");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" S ...");
jComboBox1.addItem("Systemrole");
jComboBox1.addItem("Systemuser");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" T ...");
jComboBox1.addItem("Template");
jComboBox1.addItem("TemplateCategory");
jComboBox1.addItem("TemplateField");
jComboBox1.addItem("TemplateWorkflow");
jComboBox1.addItem("TimeForInitialTraining");
jComboBox1.addItem("TrainingParicipant");
jComboBox1.addItem("TrainingSession");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" U ...");
jComboBox1.addItem("Usergroup");
jComboBox1.addItem("User2Systemrole");
jComboBox1.addItem("User2Usergroup");
jComboBox1.addItem("User2WFRole");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" V ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" W ...");
jComboBox1.addItem("WFRole");
jComboBox1.addItem("WFRole2WFStatus");
jComboBox1.addItem("WFRole2WFTrans");
jComboBox1.addItem("WFStatus");
jComboBox1.addItem("WFStatusphases");
jComboBox1.addItem("WFStatus Properties");
jComboBox1.addItem("WFTransition");
jComboBox1.addItem("WFTransitionConditions");
jComboBox1.addItem("WFTransitionConstraints");
jComboBox1.addItem("WFTransitionFinalizers");
jComboBox1.addItem("WFTransitionProperties");
jComboBox1.addItem("WFWorkflow");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" X ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" Y ...");
jComboBox1.addItem("-----------------------------------------------");
jComboBox1.addItem(" Z ...");
cp.add(jComboBox1);
jTextField1.setBounds(250, 48, 233, 80);
jTextField1.setText("SELECT * FROM " );
cp.add(jTextField1);
jButton1.setBounds(288, 152, 150, 41);
jButton1.setText("Ausführen");
cp.add(jButton1);
jLabel1.setBounds(24, 24, 114, 16);
jLabel1.setText("Tabelle auswählen");
jLabel1.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(jLabel1);
jLabel2.setBounds(232, 24, 131, 16);
jLabel2.setText("SQL-Befehl eingeben:");
jLabel2.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(jLabel2);
jTextArea1.setText("");
jTextArea1.setBounds(16, 232, 433, 201);
cp.add(jTextArea1);
jButton2.setBounds(40, 152, 150, 41);
jButton2.setText("Verbinden/Trennen");
cp.add(jButton2);
jButton1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
});
jButton2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
});
// Ende Komponenten
setResizable(false);
setVisible(true);
}
public static void main(String[] args) {
new Datenbank_auslesen("Oracle-Test-Datenbank-Zugriff");
Connection con = null;
Statement stmt;
ResultSet result;
String db_Url = "jdbc:oracle:thin:@kmmaster-ts:1521:XE";
String db_UserName = "xxxx";
String db_UserPw = "zzzz";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch (Exception e) {
System.out.println("Treiber konnte nicht gefunden werden "+e);
}
try{
con = DriverManager.getConnection(db_Url, db_UserName, db_UserPw);
}catch(Exception e) {
e.printStackTrace();
}
finally{
if(null != result) {
try{result.close();} catch(Exception ex) {}
}
if(null != stmt) {
try{stmt.close();} catch(Exception ex) {}
}
if(null != con) {
try{con.close();} catch(Exception ex) {}
}
}
}
}
Fehlermeldung:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The local variable result may not have been initialized
The local variable result may not have been initialized
The local variable stmt may not have been initialized
The local variable stmt may not have been initialized
at Datenbank_auslesen.main(Datenbank_auslesen.java:249)
Ich werd mich mal währenddessen etwas schlauer machen, wie das nun mit dem Button t, das wurmt mich derzeit ziemlich...
Bin aber trotzdem über jeden Lösungsvorschlag (wie gesagt, bitte MIT beispielcode, wenn ihr grad was auf Lager habt) dankbar!
Zuletzt bearbeitet: