Fabio Hellmann
Erfahrenes Mitglied
Bitte verwende die Java-Codetags. Da da der Code gehighlighted wird.
Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
SQLException reason = null;
for(DriverInfo aDriver : registeredDrivers) {
// If the caller does not have permission to load the driver then
// skip it.
if(isDriverAllowed(aDriver.driver, callerCL)) {
try {
println(" trying " + aDriver.driver.getClass().getName());
Connection con = aDriver.driver.connect(url, info);
if (con != null) {
// Success!
println("getConnection returning " + aDriver.driver.getClass().getName());
return (con);
}
} catch (SQLException ex) {
if (reason == null) {
reason = ex;
}
}
public static Connection getConnection(String url)
throws SQLException {
java.util.Properties info = new java.util.Properties();
// Gets the classloader of the code that called this method, may
// be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader();
return (getConnection(url, info, callerCL));
}
public static synchronized Database getInstance() throws SQLException {
if(instance == null) instance = new Database();
return instance;
}
private Database() throws SQLException {
connection = DriverManager.getConnection(CONN_STRING);
StatusBar.getInstance().setText(3, "Datenbank verbunden");
}
public PreparedStatement prepareStatement(String sql) throws SQLException {
return connection.prepareStatement(sql);
}
public void close() throws SQLException {
if(!locked) {
connection.close();
instance = null;
} else closeWhenUnlock = true;
}
private boolean locked = false;
private boolean closeWhenUnlock = false;
public static synchronized Database getInstance() throws SQLException {
if(instance == null) instance = new Database();
return instance;
}
private Database() throws SQLException {
connection = DriverManager.getConnection(CONN_STRING);
StatusBar.getInstance().setText(3, "Datenbank verbunden");
}
public void update(int selectID) throws SQLException {
if(parent != null) this.project = parent.getProject();
listModel.removeAllElements();
Customer select = null;
for(Customer customer: Database.getInstance().getCustomers()) {
listModel.addElement(customer);
if(customer.getDatabaseID() == selectID) select = customer;
}
getList().setSelectedValue(select, true);
getList().repaint();
if(select == null) getSelectButton().setEnabled(false);
}
public CustomerPanel(Maintenance parent) throws SQLException {
this.parent = parent;
nameField = new LimitedTextField(GUI.MAX_LABEL_LENGTH, GUI.FIELD);
nameField.addKeyListener(getKeyListener());
contactPersonField = new LimitedTextField(GUI.MAX_LABEL_LENGTH, GUI.FIELD);
contactPersonField.addKeyListener(getKeyListener());
adress1Field = new LimitedTextField(GUI.MAX_LABEL_LENGTH, GUI.FIELD);
adress1Field.addKeyListener(getKeyListener());
adress2Field = new LimitedTextField(GUI.MAX_LABEL_LENGTH, GUI.FIELD);
adress2Field.addKeyListener(getKeyListener());
this.setPreferredSize(new Dimension(360, 210));
this.setBorder(BorderFactory.createTitledBorder("Kunde"));
this.setLayout(new BorderLayout());
this.add(getButtonPanel(), BorderLayout.NORTH);
JScrollPane scrollPane = new JScrollPane(getList());
scrollPane.setPreferredSize(GUI.LIST);
this.add(scrollPane, BorderLayout.LINE_START);
this.add(getCenterPanel(), BorderLayout.CENTER);
getSaveButton().setEnabled(false);
getDeleteButton().setEnabled(false);
update(0);
}
public Maintenance(GUI gui) throws SQLException {
this.gui = gui;
detailsPanel = new DetailsPanel(this);
customerPanel = new CustomerPanel(this);
assemblyPanel = new AssemblyPanel(this);
processPanel = new ProcessPanel(this);
partPanel = new PartPanel(this);
attributePanel = new AttributePanel(this);
functionPanel = new FunctionPanel(this);
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
JPanel firstPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
firstPanel.add(detailsPanel);
firstPanel.add(customerPanel);
this.add(firstPanel);
JPanel secondPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
secondPanel.add(processPanel);
secondPanel.add(assemblyPanel);
secondPanel.add(partPanel);
this.add(secondPanel);
public GUI() {
super("EasyFunCalc");
this.setMinimumSize(new Dimension(1200, 900));
this.setLocationRelativeTo(null);
this.addWindowListener(this);
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource(GUI.IMG_PATH + "logo.png")));
navigationPanel = new NavigationPanel(this);
welcomePanel = navigationPanel.getWelcomePanel();
try {
projectPanel = new ProjectPanel(this);
maintenance = new Maintenance(this);
overview = new Overview(this);
calculation = new Calculation();
} catch (SQLException exception) {
MessageHandler.getInstance().showException(exception);
System.exit(0);
}
this.setLayout(new CardLayout());
this.add(welcomePanel, WELCOME);
this.add(getContentPanel(), CONTENT);
MessageHandler.getInstance().setParent(this);
public void windowClosing(WindowEvent event) {
dispose();
}
public void windowDeactivated(WindowEvent event) {}
public void windowDeiconified(WindowEvent event) {}
public void windowIconified(WindowEvent event) {}
public void windowOpened(WindowEvent event) {}
public static void main(String[] args) {
GUI gui = new GUI();
gui.setVisible(true);
}
}
Das heißt einfach nur, das die Datenbank-Datei, die du in deinem Connection-String angegeben hast bzw. als Datenquelle in ODBC eingetragen hast, nicht gefunden werden konnte.Code:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Datei '(unbekannt)' nicht gefunden.
Trag die Datei als ODBC Quelle ein bzw. berichtige den Connection String.Danke, ich brauch Vorschlag, wie kann ich am besten das Problem beheben ?
"create odbc data source"Danke , kannst du bitte mal genau sagen, wo und wie ich eintragen kann? Danke sehr !
public class Database {
private static Database instance;
private final static String CONN_STRING = "jdbc:odbc:EasyFunCalc_DB";
private Connection connection;
private boolean locked = false;
private boolean closeWhenUnlock = false;
public static synchronized Database getInstance() throws SQLException {
if(instance == null) instance = new Database();
return instance;
}
private Database() throws SQLException {
connection = DriverManager.getConnection(CONN_STRING);
StatusBar.getInstance().setText(3, "Datenbank verbunden");
}
public PreparedStatement prepareStatement(String sql) throws SQLException {
return connection.prepareStatement(sql);
}
Äh, ja. Google?Ich hab gerade gesucht und leider "create odbc code.." nicht in code gefunden.