List:MySQL and Java« Previous MessageNext Message »
From:Viva Chu Date:April 23 2004 10:27pm
Subject:RE: Insert/update preparedStatement bind variables
View as plain text  
Yes, I'm explicitly calling statement.executeUpdate; this is what causes the
exception.  I just forgot to include that in my code snippet. 

-----Original Message-----
From: Mark Matthews [mailto:mark@stripped] 
Sent: Friday, April 23, 2004 3:22 PM
To: Viva Chu
Cc: java@stripped
Subject: Re: Insert/update preparedStatement bind variables

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Viva Chu wrote:

> Resending... Anyone have any ideas as to what may be going on?  Seems 
> like this may be a simple config issue as I've found numerous examples 
> of inserts/updates on the web that use bind variables.  I can't get 
> any
of them
> to work.
>
> -----Original Message-----
> From: Viva Chu [mailto:viva.chu@stripped]
> Sent: Monday, April 19, 2004 10:44 PM
> To: java@stripped
> Subject: Insert/update preparedStatement bind variables
>
> I can't get insert or update prepared statements to work if I set bind 
> variables through my prepard statement.  However, if I include the
variables
> inline the SQL then my insert/updates work fine.  I am using MySQL 
> 4.0.18 and Jconnector 3.0.11.  Any ideas on what I am doing wrong 
> would be very much appreciated.  Oddly setting bind variables to 
> regular select
statements
> work fine.
>
> Code...
>     StringBuffer sb = new StringBuffer();
>     sb.append("update users set first_name=? where id=1");
>     Connection connection = getConnection();
>     PreparedStatement statement =
> connection.prepareStatement(sb.toString());
>     statement.setString(1, "Viva");
>
> Throws...
>
> java.sql.SQLException: Syntax error or access violation,  message from
> server: "You have an error in your SQL syntax.  Check the manual that 
> corresponds to your MySQL server version for the right syntax to use
near '?
> where id=1' at line 1"
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1905)
> 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1109)
> 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1203)
> 	at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1164)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2087)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2037)
> 	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1252)
> 	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1198)
> 	at
>
org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(Delegating
> PreparedStatement.java:208)
> 	at
>
org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(Delegating
> PreparedStatement.java:208)
>

It looks like for some reason Apache's DelegatingPreparedStatement is
calling MySQL's _Statement_.executeUpdate()...Are you somewhere calling
'executeUpdate(String)'?

	-Mark


- --
Mr. Mark Matthews
MySQL AB, Software Development Manager, J2EE and Windows Platforms
Office: +1 708 332 0507
www.mysql.com

Meet the MySQL Team! April 14-16, 2004 http://www.mysql.com/uc2004/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAiZb7tvXNTca6JD8RAjL5AJ9mHZ6w5mWMNyz812XjYPiwaRVa/ACgq1IA
oXstpjd/xRC1/2nBfIg4YjM=
=AAfW
-----END PGP SIGNATURE-----

--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:    http://lists.mysql.com/java?unsub=1

Thread
Insert/update preparedStatement bind variablesViva Chu20 Apr
RE: Insert/update preparedStatement bind variablesViva Chu24 Apr
Re: Insert/update preparedStatement bind variablesMark Matthews24 Apr
  • RE: Insert/update preparedStatement bind variablesViva Chu24 Apr