Re: Why oh why don't my updates stick?
Christopher Lambert <[email protected]> Wed, 26 Jul 2006 09:51:18 -0600
| Newsgroups | gmane.comp.db.mckoi |
|---|---|
| Message-ID | <[email protected]> |
Mary, Are you missing a commit or do you have autocommit enabled somewhere? Chris [email protected] wrote: >Hi everyone... I'm a newbie to this whole SQL & McKoi world, so forgive >me if I'm doing something really basic wrong here, but I'm at my wits >end trying to figure out what it is. > >I'm using McKoi for JUnit tests of code where a MS SQL server would >otherwise be used. The code works just fine against the SQL Server >database, but my updates against McKoi just do not stick. There is no >error message or exception. It all appears to work fine, only the data >is unchanged so all my update tests fail. Add's work just fine, it is >only the updates that are the problem. Here is a sample bit of code. > >>From the system code: > > public void updateLineOfBusiness(LineOfBusiness lob) throws >DtsServiceException{ > > if (lob.getId()==-1) > throw new DtsServiceException("Cannot update, >line of business id is not set."); > StringBuffer updateSQL = new StringBuffer(); > updateSQL.append("UPDATE "); > updateSQL.append(LOB_TABLE); > updateSQL.append(" SET >").append(LOB_CODE_COLUMN).append("=\'"); > updateSQL.append(lob.getCode()).append("\'"); > updateSQL.append(", >").append(LOB_SHORT_NAME_COLUMN).append("='"); > updateSQL.append(lob.getShortName()).append("\'"); > updateSQL.append(", >").append(LOB_NAME_COLUMN).append("=\'"); > updateSQL.append(lob.getName()).append("\'"); > updateSQL.append(", ").append(LOB_DESC_COLUMN); > >updateSQL.append("=\'").append(lob.getDescription()).append("\'"); > updateSQL.append(" WHERE >").append(LOB_ID_COLUMN).append("=\'"); > updateSQL.append(lob.getId()).append("\'"); > > try { > log.debug("Updating line of business " + >lob.toString()); > log.debug(updateSQL); > Statement updateStatement = >dbConnection.createStatement(); > updateStatement.execute(updateSQL.toString()); > } catch (SQLException e) { > throw new DtsServiceException("SQL error >updating line of business: " + lob); > } > } > >>From the test case: > > public void testUpdateLineOfBusiness(){ > try{ > dts.createTable_LOB(); > > Connection connection = dts.getConnection(); > LineOfBusinessServiceImpl service = new >LineOfBusinessServiceImpl(connection); > > //Get a line of business directly > Statement statement = >connection.createStatement(); > statement.execute("Select * from >T_LINE_OF_BUSINESS"); > ResultSet results = statement.getResultSet(); > results.next(); > LineOfBusiness lob = >getNextLineOfBusiness(results); > > //Change and update it > lob.setDescription("My test description"); > lob.setName("My test LOB"); > lob.setShortName("test"); > service.updateLineOfBusiness(lob); > > //Make sure we can get the updated result >through the service > LineOfBusiness resultLOB = >service.getLineOfBusinessById(lob.getId()); > assertEquals(lob, resultLOB); > > } catch(Exception e){ > log.error(e.getMessage(), e); > fail(); > } > } > > >Thanks much for the help in advance! > >Mary Whetsel > > > > > > > >--------------------------------------------------------------- >Mckoi SQL Database mailing list http://www.mckoi.com/database/ >To unsubscribe, send a message to [email protected] > > > > --------------------------------------------------------------- Mckoi SQL Database mailing list http://www.mckoi.com/database/ To unsubscribe, send a message to [email protected]