Re: [JDBC] Does PG's JDBC support prepared statements at all?
Remove the single quotes from '?' there is no need for them. Dave -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Dr. Evil Sent: October 20, 2001 7:14 PM To: [EMAIL PROTECTED] Subject: [JDBC] Does PG's JDBC support prepared statements at all? There is a bunch of documentation for prepared statements in PG's JDBC, it seems that the only thing prepared statements do is throw exceptions. Here's some code I'm trying: String newvalue = This is a new value; int accountnumber = 54; String qstring = UPDATE foo SET message = '?' WHERE number = ?; PreparedStatement st = db.prepareStatement(qstring); st.setString(1, newvalue); st.setInt(2, accountnumber); st.execute(); st.clearParameters(); st.close(); and I always get a Parameter index out of range error, which seems impossible. Any idea what's going on? ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [JDBC] Does PG's JDBC support prepared statements at all?
On Sun, 21 Oct 2001 11:37:29 +0900, you wrote: So I guess what is happening is that the preparedstatement parser ignores quoted question marks I hope not. I hope it sets the field to a literal '?' :-) Regards, René Pijlman [EMAIL PROTECTED] ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq.html
Re: [JDBC] Does PG's JDBC support prepared statements at all?
On 20 Oct 2001 23:14:22 -, you wrote: There is a bunch of documentation for prepared statements in PG's JDBC, it seems that the only thing prepared statements do is throw exceptions. I suggest you read some basic JDBC documentation. This is really not PostgreSQL specific. Checkout http://www.javaskyline.com/learnjdbc.html Regards, René Pijlman [EMAIL PROTECTED] ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [JDBC] Does PG's JDBC support prepared statements at all?
On Sun, Oct 21, 2001 at 02:06:21PM +0200, Rene Pijlman wrote: On Sun, 21 Oct 2001 11:37:29 +0900, you wrote: So I guess what is happening is that the preparedstatement parser ignores quoted question marks I hope not. I hope it sets the field to a literal '?' :-) I meant ignores them in terms of not handling them as normal variable placement holders or whatever the correct terminology is :) But I guess that wasn't crystal clear in the way that I phrased it. Tom. -- Thomas O'Dowd. - Nooping - http://nooper.com [EMAIL PROTECTED] - Testing - http://nooper.co.jp/labs ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
Re: [JDBC] Does PG's JDBC support prepared statements at all?
On Sat, Oct 20, 2001 at 11:14:22PM -, Dr. Evil wrote: There is a bunch of documentation for prepared statements in PG's JDBC, it seems that the only thing prepared statements do is throw exceptions. Here's some code I'm trying: String newvalue = This is a new value; int accountnumber = 54; String qstring = UPDATE foo SET message = '?' WHERE number = ?; PreparedStatement st = db.prepareStatement(qstring); st.setString(1, newvalue); st.setInt(2, accountnumber); st.execute(); st.clearParameters(); st.close(); and I always get a Parameter index out of range error, which seems impossible. Any idea what's going on? You shouldn't quote the ? for the string. By calling the setString() method, it will add the quotes for you. So I guess what is happening is that the preparedstatement parser ignores quoted question marks and just finds 1 variable, when you call setstring on 1 it sets the number= part, and then when you call setInt(2) you are getting the index out of range. The proper qstring should be: UPDATE foo SET message = ? WHERE number = ? Cheers, Tom. -- Thomas O'Dowd. - Nooping - http://nooper.com [EMAIL PROTECTED] - Testing - http://nooper.co.jp/labs ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster