Ho questa classe per interfacciarmi ad un database MySQL:
Ora ho dovuto passare ad un DB ACCESS e quindi ho creato un'altra classe che estende la prima:codice:import java.sql.*; public class SQLInterface { protected Statement stmt; protected Connection conn; protected ResultSet rset; public PreparedStatement[] pstmt; // array dove devo mettere le query piu' usate public final String PREFIX = ""; public SQLInterface() throws SQLException{ try { // Load the MySQL JDBC driver try { Class.forName("org.gjt.mm.mysql.Driver"); } catch (ClassNotFoundException e) { System.out.println ("MySQL device driver does not exist"); System.exit(1); } }catch (Exception e) {} // System.out.println("Driver ok"); } public void connect(){ try{ // Connect to the database // You can put a database name after the @ sign in the connection URL. // System.out.println("Tento la conn"); conn = DriverManager.getConnection ("jdbc:mysql://localhost/Assist","root",""); //System.out.println("Connessione ok"); // Create a Statement stmt = conn.createStatement (); }catch(SQLException e){ System.out.println("Error accessing DB "); System.out.println(" Error code is : "+e.getErrorCode()); System.out.println(" Error message is :"+e.getMessage()); } } public ResultSet SelectQuery(String query) throws SQLException{ // Select the ENAME column from the EMP table rset = stmt.executeQuery (query); return rset; } public void Query(String query) throws SQLException { int result = stmt.executeUpdate(query); } public void disconnect(){ try{ // Close the Statement stmt.close(); rset.close(); // Close the connection conn.close(); }catch(SQLException e){ System.out.println("Error accessing DB "); System.out.println(" Error code is : "+e.getErrorCode()); System.out.println(" Error message is :"+e.getMessage()); } } }
Quindi ho semplicemente sostituito nel mio codice gli oggetti SQLInterface con AccessInterface.codice:public class AccessInterface extends SQLInterface{ public AccessInterface() throws SQLException{ Connection connessione = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String qsdb = "jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=e:/assist/db1.mdb"; connessione = DriverManager.getConnection(qsdb,"",""); System.out.println("connessione al db riuscita"); stmt = connessione.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE ); }catch(SQLException e){ System.out.println("Error accessing DB "); System.out.println(" Error code is : "+e.getErrorCode()); System.out.println(" Error message is :"+e.getMessage()); }catch (Exception e) { System.out.println(e.getLocalizedMessage() + " connessione al db NON riuscita"); } } public void connect(){} }
Funziona tutto solo che in console mi da questo errore:
Non riesco a capire a cosa si riferisca qualcuno sa darmi una mano????codice:connessione al db riuscita Error accessing DB Error code is : 0 Error message is :ResultSet is closed

Rispondi quotando

