List:General Discussion« Previous MessageNext Message »
From:yilmaz Date:November 20 2001 2:05pm
Subject:Re: why doesn't prepared statement work?
View as plain text  
Well,
i am answering  my own question.
It was keeping  telling me that there is a syntax error.
However, the real problem was at the bottom the preparedstatement code
snippet
"stmt.executeUpdate(query);"
statement should have been
"stmt.executeUpdate();" (without parameter)
Wouldn't it make our lives easier if MySQL had thrown a sensible
and a logical error message so that developers need not to
waste a lot of time on a fairly small problem?

----- Original Message -----
From: "yilmaz" <yilmaz@stripped>
To: <mysql@stripped>
Sent: Tuesday, November 20, 2001 9:08 PM
Subject: Re: why doesn't prepared statement work?


> Thanks Neil,
> even with only one parameter it doesn't work.
> it keeps throwing:
>
> javax.servlet.ServletException: Syntax error or access violation: You have
> an error in your SQL syntax near '?)' at line 1
>
> when i replace ? with '?'  it throws:
> java.lang.ArrayIndexOutOfBoundsException
> at org.gjt.mm.mysql.PreparedStatement.set(PreparedStatement.java:1192)
> at
> org.gjt.mm.mysql.PreparedStatement.setString(PreparedStatement.java:581)
>
> It is very strange , isn't it?
>
> ----- Original Message -----
> From: "DL Neil" <PHPml@stripped>
> To: "yilmaz" <yilmaz@stripped>; <mysql@stripped>
> Sent: Tuesday, November 20, 2001 7:29 PM
> Subject: Re: why doesn't prepared statement work?
>
>
> > Yilmaz,
> > Recommend you simplify. Test on (say) the first five fields, then the
next
> five,... and try to work out which
> > field is causing the issue, then analyse by narrowing down until you
> figure it out.
> > The data value (in the (?,?,?,...) list, must be formatted to suit the
> type in the column list.
> > Regards,
> > =dn
> >
> > ----- Original Message -----
> > From: "yilmaz" <yilmaz@stripped>
> > To: <mysql@stripped>
> > Sent: 20 November 2001 10:18
> > Subject: Re: why doesn't prepared statement work?
> >
> >
> > > Thanks Hans,
> > > when i replcaed  ? with "?" , this time i ma having
> > >
> > > java.lang.ArrayIndexOutOfBoundsException
> > > at org.gjt.mm.mysql.PreparedStatement.set(PreparedStatement.java:1192)
> > > at
> > >
org.gjt.mm.mysql.PreparedStatement.setString(PreparedStatement.java:581)
> > >
> > > error message.
> > > However, i am sure there are exactly 19 fieldnames  and 19 "?"s, also
in
> the
> > > database there
> > > are 19 columns exactly matching the filednames.
> > > what could be wrong now?
> > >
> > >
> > > ----- Original Message -----
> > > From: "Hans" <hans@stripped>
> > > To: "yilmaz" <yilmaz@stripped>
> > > Sent: Wednesday, November 21, 2001 8:48 AM
> > > Subject: Re: why doesn't prepared statement work?
> > >
> > >
> > > > maybe u should use '?' instead of ?.
> > > > Btw, isn't that special char which need function htmlspecialchars()
?
> > > >
> > > > ----- Original Message -----
> > > > From: "yilmaz" <yilmaz@stripped>
> > > > To: <mysql@stripped>
> > > > Sent: Tuesday, November 20, 2001 1:11 AM
> > > > Subject: why doesn't prepared statement work?
> > > >
> > > >
> > > > > Hi all,
> > > > > i have a strange situation here,
> > > > > i am trying to execute an sql insert via prepared statements.
> > > > > though it is a simple insert process, i am having a syntax error
> > > message.
> > > > > Doesn't mysql support this?
> > > > > can someone please tell me what is wrong with this query?
> > > > >
> > > > > String query="insert into temp(member ,ename,cname,jname ,sex
> ,age
> ,"+
> > > > >      "nation ,prf ,occ  ,educ ,address ,city
> ,res_city,res_address
> ,"+
> > > > >      "htel ,mtel,otel ,fax ,email) "+
> > > > >     " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
> > > > >         PreparedStatement stmt=conn.prepareStatement(query);
> > > > >
> > > > >     stmt.setString(1,member);
> > > > >     stmt.setString(2,ename);
> > > > >     stmt.setString(3,cname);
> > > > >     stmt.setString(4,jname);
> > > > >     stmt.setString(5,sex);
> > > > >     stmt.setInt(6,age);
> > > > >     stmt.setString(7,nation);
> > > > >     stmt.setString(8,prf);
> > > > >     stmt.setString(9,occ);
> > > > >     stmt.setString(10,educ);
> > > > >     stmt.setString(11,address);
> > > > >     stmt.setString(12,city);
> > > > >     stmt.setString(13,res_city);
> > > > >     stmt.setString(14,res_address);
> > > > >     stmt.setString(15,htel);
> > > > >     stmt.setString(16,mtel);
> > > > >     stmt.setString(17,otel);
> > > > >     stmt.setString(18,fax);
> > > > >     stmt.setString(19,email);
> > > > >    stmt.executeUpdate(query);
> > > > >
> > > > >   stmt.close();
> > > > >   conn.close();
> > > > >
> > > > > the error message says:
> > > > > javax.servlet.ServletException: Syntax error or access
> violation:
> You
> > > have
> > > > > an error in your SQL syntax near
> > > '?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'
> > > > at
> > > > > line 1
> > > > >
> > > > >
> > > > > thanks a lot in advance :)
> > > > >
> > > > >
> > > > >
> > > >
> > ---------------------------------------------------------------------
> > > > > Before posting, please check:
> > > > >    http://www.mysql.com/manual.php   (the manual)
> > > > >    http://lists.mysql.com/           (the list archive)
> > > > >
> > > > > To request this thread, e-mail
> <mysql-thread91757@stripped>
> > > > > To unsubscribe, e-mail
> > > > <mysql-unsubscribe-hans=trimegah.com@stripped>
> > > > > Trouble unsubscribing? Try:
> http://lists.mysql.com/php/unsubscribe.php
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > Before posting, please check:
> > >    http://www.mysql.com/manual.php   (the manual)
> > >    http://lists.mysql.com/           (the list archive)
> > >
> > > To request this thread, e-mail <mysql-thread91764@stripped>
> > > To unsubscribe, e-mail
> <mysql-unsubscribe-PHPml=dande.homechoice.co.uk@stripped>
> > > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > Before posting, please check:
> >    http://www.mysql.com/manual.php   (the manual)
> >    http://lists.mysql.com/           (the list archive)
> >
> > To request this thread, e-mail <mysql-thread91770@stripped>
> > To unsubscribe, e-mail
> <mysql-unsubscribe-yilmaz=hwajet.com.tw@stripped>
> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> >
> >
>
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <mysql-thread91775@stripped>
> To unsubscribe, e-mail
<mysql-unsubscribe-yilmaz=hwajet.com.tw@stripped>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>


Thread
why doesn't prepared statement work?yilmaz20 Nov
  • Re: why doesn't prepared statement work?yilmaz20 Nov
  • Re: why doesn't prepared statement work?DL Neil20 Nov
  • Re: why doesn't prepared statement work?yilmaz20 Nov
  • Re: why doesn't prepared statement work?yilmaz20 Nov
    • Re: why doesn't prepared statement work?Dan Nelson20 Nov