Discussion:
Why oh why don't my updates stick?
M***@wellsfargo.com
2006-07-26 15:41:46 UTC
Permalink
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.
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);
}
}
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 mckoidb-***@mckoi.com
Christopher Lambert
2006-07-26 15:51:18 UTC
Permalink
Mary,

Are you missing a commit or do you have autocommit enabled somewhere?

Chris
Post by M***@wellsfargo.com
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.
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);
}
}
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/
---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com
M***@wellsfargo.com
2006-07-26 15:54:34 UTC
Permalink
No... I have no commit... Didn't know I needed one, since it all works
fine on SQL Server.

How would I enable autocommit? And is there a reason I wouldn't want to
do that?


Mary Whetsel
Apps Systems Engineer
3i Development
Phone: 612.667.4411

-----Original Message-----
From: ***@mckoi.com [mailto:***@mckoi.com] On Behalf Of
Christopher Lambert
Sent: Wednesday, July 26, 2006 10:51 AM
To: ***@mckoi.com
Subject: Re: Why oh why don't my updates stick?

Mary,

Are you missing a commit or do you have autocommit enabled somewhere?

Chris
Post by M***@wellsfargo.com
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.
public void updateLineOfBusiness(LineOfBusiness lob) throws
DtsServiceException{
if (lob.getId()==-1)
throw new DtsServiceException("Cannot update,
line of business id is
Post by M***@wellsfargo.com
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());
Post by M***@wellsfargo.com
log.debug(updateSQL);
Statement updateStatement =
dbConnection.createStatement();
updateStatement.execute(updateSQL.toString());
} catch (SQLException e) {
throw new DtsServiceException("SQL error
" + lob);
}
}
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
Post by M***@wellsfargo.com
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
---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/ To
unsubscribe, send a message to mckoidb-***@mckoi.com





---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com
Bayless Kirtley
2006-07-26 19:15:21 UTC
Permalink
The JDBC standard is for autocommit to be off by default. You have to either
commit each transaction or turn autocommit on. The code to do so is

connection.autocommit(true);

where connection is your preestablished JDBC Connection, the one you will
use to make the updates.

Hope this helps

Bayless


----- Original Message -----
From: <***@wellsfargo.com>
To: <***@mckoi.com>
Sent: Wednesday, July 26, 2006 10:54 AM
Subject: RE: Why oh why don't my updates stick?


No... I have no commit... Didn't know I needed one, since it all works
fine on SQL Server.

How would I enable autocommit? And is there a reason I wouldn't want to
do that?


Mary Whetsel
Apps Systems Engineer
3i Development
Phone: 612.667.4411

-----Original Message-----
From: ***@mckoi.com [mailto:***@mckoi.com] On Behalf Of
Christopher Lambert
Sent: Wednesday, July 26, 2006 10:51 AM
To: ***@mckoi.com
Subject: Re: Why oh why don't my updates stick?

Mary,

Are you missing a commit or do you have autocommit enabled somewhere?

Chris
Post by M***@wellsfargo.com
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.
public void updateLineOfBusiness(LineOfBusiness lob) throws
DtsServiceException{
if (lob.getId()==-1)
throw new DtsServiceException("Cannot update,
line of business id is
Post by M***@wellsfargo.com
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());
Post by M***@wellsfargo.com
log.debug(updateSQL);
Statement updateStatement =
dbConnection.createStatement();
updateStatement.execute(updateSQL.toString());
} catch (SQLException e) {
throw new DtsServiceException("SQL error
" + lob);
}
}
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
Post by M***@wellsfargo.com
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
---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/ To
unsubscribe, send a message to mckoidb-***@mckoi.com





---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com



---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com
M***@wellsfargo.com
2006-07-26 20:05:55 UTC
Permalink
Actually... It doesn't...

First I tried turning on the autocommit. That had the same results.

Then I turned that off again, and I've added the commit to the update
method. Unfortunately, I am still getting the same results.

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);

updateSQL.append("=\'").append(lob.getShortName()).append("\'");
updateSQL.append(", ").append(LOB_NAME_COLUMN);

updateSQL.append("=\'").append(lob.getName()).append("\'");
updateSQL.append(", ").append(LOB_DESC_COLUMN);

updateSQL.append("=\'").append(lob.getDescription()).append("\'");
updateSQL.append(" WHERE
").append(LOB_ID_COLUMN).append("=\'").append(lob.getId()).append("\'");

try {
log.debug("Updating line of business " +
lob.toString());
log.debug(updateSQL);
Statement updateStatement =
dbConnection.createStatement();
updateStatement.execute(updateSQL.toString());
dbConnection.commit();
} catch (SQLException e) {
throw new DtsServiceException("SQL error
updating line of business: " + lob);
}
}

Mary Whetsel
Apps Systems Engineer
3i Development
Phone: 612.667.4411

-----Original Message-----
From: ***@mckoi.com [mailto:***@mckoi.com] On Behalf Of Bayless
Kirtley
Sent: Wednesday, July 26, 2006 2:15 PM
To: ***@mckoi.com
Subject: Re: Why oh why don't my updates stick?

The JDBC standard is for autocommit to be off by default. You have to
either commit each transaction or turn autocommit on. The code to do so
is

connection.autocommit(true);

where connection is your preestablished JDBC Connection, the one you
will use to make the updates.

Hope this helps

Bayless


----- Original Message -----
From: <***@wellsfargo.com>
To: <***@mckoi.com>
Sent: Wednesday, July 26, 2006 10:54 AM
Subject: RE: Why oh why don't my updates stick?


No... I have no commit... Didn't know I needed one, since it all works
fine on SQL Server.

How would I enable autocommit? And is there a reason I wouldn't want to
do that?


Mary Whetsel
Apps Systems Engineer
3i Development
Phone: 612.667.4411

-----Original Message-----
From: ***@mckoi.com [mailto:***@mckoi.com] On Behalf Of
Christopher Lambert
Sent: Wednesday, July 26, 2006 10:51 AM
To: ***@mckoi.com
Subject: Re: Why oh why don't my updates stick?

Mary,

Are you missing a commit or do you have autocommit enabled somewhere?

Chris
Post by M***@wellsfargo.com
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.
public void updateLineOfBusiness(LineOfBusiness lob) throws
DtsServiceException{
if (lob.getId()==-1)
throw new DtsServiceException("Cannot update,
line of business id is
Post by M***@wellsfargo.com
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());
Post by M***@wellsfargo.com
log.debug(updateSQL);
Statement updateStatement =
dbConnection.createStatement();
updateStatement.execute(updateSQL.toString());
} catch (SQLException e) {
throw new DtsServiceException("SQL error
" + lob);
}
}
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
Post by M***@wellsfargo.com
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
---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/ To
unsubscribe, send a message to mckoidb-***@mckoi.com





---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com



---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com





---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com
Jim McBeath
2006-07-26 22:13:50 UTC
Permalink
On Wed, Jul 26, 2006 at 03:05:55PM -0500, ***@wellsfargo.com wrote:

Instead of using
Post by M***@wellsfargo.com
updateStatement.execute(updateSQL.toString());
try

int n = updateStatement.executeUpdate(updateSQL.toString());

The return value (n) is the number of rows updated, so you can see if
mckoi thinks your statement should have updated a row.

--
Jim


---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com
M***@wellsfargo.com
2006-07-31 19:49:42 UTC
Permalink
Thanks much for the suggestion Jim.

Turns out that I wasn't updating any rows... The field I was using in
the Where clause was a long, and McKoi will not find the row if quotes
are used. (LOB_ID=1 not LOB_ID='1') Evidently MS SQL server is more
forgiving.

Thanks again, I feel much more sane now that my JUnit tests run green
again. :-D


Mary Whetsel


-----Original Message-----
From: ***@mckoi.com [mailto:***@mckoi.com] On Behalf Of Jim
McBeath
Sent: Wednesday, July 26, 2006 5:14 PM
To: ***@mckoi.com
Subject: Re: Why oh why don't my updates stick?

On Wed, Jul 26, 2006 at 03:05:55PM -0500, ***@wellsfargo.com
wrote:

Instead of using
Post by M***@wellsfargo.com
updateStatement.execute(updateSQL.toString());
try

int n = updateStatement.executeUpdate(updateSQL.toString());

The return value (n) is the number of rows updated, so you can see if
mckoi thinks your statement should have updated a row.

--
Jim


---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/ To
unsubscribe, send a message to mckoidb-***@mckoi.com





---------------------------------------------------------------
Mckoi SQL Database mailing list http://www.mckoi.com/database/
To unsubscribe, send a message to mckoidb-***@mckoi.com

Continue reading on narkive:
Loading...