We help IT Professionals succeed at work.

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

ethnarch
ethnarch asked
on
Medium Priority
1,063 Views
Last Modified: 2012-06-27
::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;
    }
Comment
Watch Question

Try using crs.setTableName("myTableName") before updating the database as follows:

  crs.setTableName("myTableName");
  crs.acceptChanges(con);

_______________

  Nayer Naguib

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
::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

Author

Commented:
::nevermind i typed the tablename wrong, my mistake i think it's working now

Author

Commented:
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.