List:MySQL and Java« Previous MessageNext Message »
From:dev Date:August 27 2004 4:53am
Subject:PreparedStatements and "ON DUPLICATE KEY UPDATE ..."
View as plain text  
(if there has been some discussion about this already, please let me 
know. searches on this list in the last 365 for either "ON DUPLICATE 
KEY" or "PREPARED STATEMENT DUPLICATE KEY" yielded no relevant 
discussions, but maybe there's a better search i could do. i couldn't 
find anything about it in the connector j docs either, so maybe asking 
here can yield some answers, or at least some commiseration.

i'm trying to prepare and bind statements a la
	
	PreparedStatement st = conn.prepareStatement(
		"  INSERT INTO blah ( col1, col2 ) VALUES ( ?, ? ) " + // col1 is 
prikey, let's say
		" ON DUPLICATE KEY UPDATE col1 = ?, col2 = ? "
	);
	
	st.setBlah( 1, someCol1Val );
	st.setBlah( 3, someCol1Val );
	st.setBlah( 2, someCol2Val );
	st.setBlah( 4, someCol2Val );

	...

but it only seems to work under the insert conditions. note -- it 
doesn't fail or throw a SQLException, etc, it just leaves things 
untouched. is it supported and i'm doing something wrong, or is it 
unsupported (in which case let's just agree that at least i'm not 
wrong:)

jon

Thread
PreparedStatements and "ON DUPLICATE KEY UPDATE ..."dev27 Aug