Hallo,
ich versuche Daten in eine MSAccess mdb zu schreiben.
Zuerst hole ich alle Daten, dann verarbeite ich diese in einer Schleife in der ich das Ergebnis wieder reinschreibe.
Jedesmal beim 2. Update bekomme ich eine Exception
Ich weiss nicht warum, weil ich auch darauf achte nur eine Instantz zu öffen -> Singleton
ich versuche Daten in eine MSAccess mdb zu schreiben.
Zuerst hole ich alle Daten, dann verarbeite ich diese in einer Schleife in der ich das Ergebnis wieder reinschreibe.
Jedesmal beim 2. Update bekomme ich eine Exception
Code:
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.throwGenericSQLException(JdbcOdbc.java:7087)
at sun.jdbc.odbc.JdbcOdbc.SQLAllocStmt(JdbcOdbc.java:174)
at sun.jdbc.odbc.JdbcOdbcConnection.createStatement(JdbcOdbcConnection.java:413)
at sun.jdbc.odbc.JdbcOdbcConnection.createStatement(JdbcOdbcConnection.java:396)
at database.MSAccess.getStatement(MSAccess.java:73)
Ich weiss nicht warum, weil ich auch darauf achte nur eine Instantz zu öffen -> Singleton
Code:
public class MSAccess {
protected static DatabaseDSN dsn = null;
protected static Connection con = null;
protected static MSAccess instance = null;
/** Creates a new instance of MSAccess */
protected MSAccess() {
}
public static void setDSN(DatabaseDSN d) {
dsn = d;
}
protected void connect() throws SQLException {
Messenger.send("Connecting to database: " + dsn.url);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(ClassNotFoundException e){
e.printStackTrace();
}
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + dsn.url, dsn.user, dsn.password);
}
public Connection getConnection() throws SQLException {
checkConnnection();
return con;
}
public void close() throws SQLException {
Messenger.send("Trying to close the connection with database: " + dsn.url);
if(con != null) con.close();
}
protected void checkConnnection() throws SQLException {
if(con == null) {
System.out.println("MSAccess connection was null");
connect();
} else {
System.out.println("MSAccess connection IS OKAY");
}
}
public static MSAccess getInstance() {
if(instance == null) instance = new MSAccess();
return instance;
}
public Statement getStatement() throws SQLException {
checkConnnection();
return con.createStatement();
}
public Statement getStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
checkConnnection();
return con.createStatement(resultSetType, resultSetConcurrency);
}
}