Link to home
Start Free TrialLog in
Avatar of ethnarch
ethnarch

asked on

keep getting an exception with cachedRowSetImpl java.sql.SQLException: writeData cannot determine table name

::When i go to accept any changes to a cachedRowSetImpl i end up getting this error.

java.sql.SQLException: writeData cannot determine table name

::The source code is as follows i first call it in one class like so

     sqlUtil.commitToDatabase(onlineSrvrNm, onlineCRS);

::And the commitToDatabase method is as follows:

    public boolean commitToDatabase(String ServerName, CachedRowSetImpl crs) {
        Connection con = null;
       
        try {
            conSet.setServer(ServerName);
            Driver d = (Driver)Class.forName( conSet.getDriver() ).newInstance();
            con = DriverManager.getConnection(conSet.getServerPath(), conSet.getUser(), conSet.getPass());
            System.out.println("sqlUtilities.commitToDatabase: Database connection established");
           
            // propagate changes and close connection
            crs.acceptChanges(con);
            crs.close();
            con.close();
           
            return true;
           
        } catch (SQLException se) {
            System.err.println("sqlUtilities.commitToDatabase:" + se.getMessage() + "Exception--" + se.toString());
                    return false;
           
        } catch (Exception e) {
            System.err.println("sqlUtilities.commitToDatabase:" + e.getMessage() + " Exception--" + e.toString());
                    return false;
        }
    }

::The error occurs on the line crs.acceptChanges(con) I also tried placing the accept changes directly in the first class instead of doing it this way and i get the same error so it's not the way i am passing it. And incase the problem is where i am populating the CachedRowSet here is the method i am using for that

 public CachedRowSetImpl getCachedRowSet(String ServerName, String sqlQry){
       
        //import com.sun.rowset.CachedRowSetImpl;
        ResultSet rs;
        Connection con = null;
        CachedRowSetImpl crs;
        try {
            conSet.setServer(ServerName);
            Driver d = (Driver)Class.forName( conSet.getDriver() ).newInstance();
            con = DriverManager.getConnection(conSet.getServerPath(), conSet.getUser(), conSet.getPass());
            System.out.println("sqlUtilities.getResultSet:Database connection established");
            Statement stmt = con.createStatement();
            rs = stmt.executeQuery(sqlQry);
            crs = new CachedRowSetImpl();
            crs.populate(rs);
           
            // note that the connection is being closed
            con.close();
            return crs;
        } catch (Exception e){
            System.err.println("sqlUtilities.getResultSet:Cannot connect to database server" + e.toString());
        }
        return null;
    }
ASKER CERTIFIED SOLUTION
Avatar of nayernaguib
nayernaguib
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ethnarch
ethnarch

ASKER

::i get this error now, but it doesn't list the 3 conflicts nor am i sure what kind of conflicts it's referring to

   3 conflicts while synchronizing Exception--javax.sql.rowset.spi.SyncProviderException: 3 conflicts while synchronizing
::nevermind i typed the tablename wrong, my mistake i think it's working now
Is it normal to have to set the tablename, I mean why doesn't it store the tablename when you populate the cachedRowSet
I think populating the cachedRowSet only adds a collection of rows to the crs object.

This is what the error indicates anyway. :-)

_______________

  Nayer Naguib