MySQLSyntaxErrorException near “?” when trying to execute PreparedStatementMySQLSyntaxErrorException when trying to execute PreparedStatementcheck the manual that corresponds to your MySQL server version for the right syntax to use near '? and password = ?' at line 1PreparedStatement throws syntax errorUsing Java and Mysql getting exception com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: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 useridMySQL and JDBC PreparedStatement using SelectHow to insert sql query in javacom.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException with PreparedStatementWhy would JDBC-MySQL throws error in your SQL syntax though my generated query works fine?JAVA JDBC mySql Prepared statement Update queryDoes a finally block always get executed in Java?When to use LinkedList over ArrayList in Java?How can I create an executable JAR with dependencies using Maven?Java PreparedStatement complaining about SQL syntax on execute()Getting com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SQL syntaxError while updating table com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExceptioncom.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException Insert mysql errorWhy does PreparedStatement (JDBC) result in a MySQLSyntaxErrorException in MySQL 5.7.9?Using Java and Mysql getting exception com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:MySQLSyntaxErrorException when trying to select from sqoop

What is a common way to tell if an academic is "above average," or outstanding in their field? Is their h-index (Hirsh index) one of them?

What Kind of Wooden Beam is this

What do you call a painting on a wall?

How can I evaluate this integral

Discrete function is also a math function?

Is there precedent or are there procedures for a US president refusing to concede to an electoral defeat?

My large rocket is still flipping over

Determine if a grid contains another grid

about academic proof-reading, what to do in this situation?

Is there a word that describes the unjustified use of a more complex word?

In Futurama, how many beings has Leela slept with?

What to do when scriptures go against conscience?

How to pass query parameters in URL in Salesforce Summer 19 Release?

How can I get people to remember my character's gender?

Game artist computer workstation set-up – is this overkill?

What does にとり mean?

Simple Derivative Proof?

Does running exec do anything?

Why did the Apollo 13 crew extend the LM landing gear?

Why does sound not move through a wall?

How do I, as a DM, handle a party that decides to set up an ambush in a dungeon?

What's the 2-minute timer on mobile Deutsche Bahn tickets?

Who filmed the Apollo 11 trans-lunar injection?

Krull dimension of the ring of global sections



MySQLSyntaxErrorException near “?” when trying to execute PreparedStatement


MySQLSyntaxErrorException when trying to execute PreparedStatementcheck the manual that corresponds to your MySQL server version for the right syntax to use near '? and password = ?' at line 1PreparedStatement throws syntax errorUsing Java and Mysql getting exception com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: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 useridMySQL and JDBC PreparedStatement using SelectHow to insert sql query in javacom.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException with PreparedStatementWhy would JDBC-MySQL throws error in your SQL syntax though my generated query works fine?JAVA JDBC mySql Prepared statement Update queryDoes a finally block always get executed in Java?When to use LinkedList over ArrayList in Java?How can I create an executable JAR with dependencies using Maven?Java PreparedStatement complaining about SQL syntax on execute()Getting com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SQL syntaxError while updating table com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExceptioncom.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException Insert mysql errorWhy does PreparedStatement (JDBC) result in a MySQLSyntaxErrorException in MySQL 5.7.9?Using Java and Mysql getting exception com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:MySQLSyntaxErrorException when trying to select from sqoop






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








4















I'm trying to execute a query using a PreparedStatement in Java.



I am getting error number 1064 when I try to execute my query (syntax error).



I have tested this in MySQL query browser with substituted values which works fine.



What's wrong with my code?



Here's the relevant code:



String query = "select MemberID, MemberName from members where MemberID = ? or MemberName = ?";
Connection conn = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
PreparedStatement s = conn.prepareStatement(query);
s.setInt(1, 2);
s.setString(2, "zen");
ResultSet rs = s.executeQuery(query);


Here's the exception I'm getting:




com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '? or MemberName
= ?' at line 1











share|improve this question



















  • 1





    give more details about the "error" - exceptions in Java have stacktraces

    – Bozho
    Nov 9 '10 at 6:56











  • Just before the executeQuery gets called I see during debugging that the parameters get substituted into the PreparedStatemet, the query becomes "com.mysql.jdbc.JDBC4PreparedStatement@6e9770a3: select MemberID, MemberName from members where MemberID = 2 or MemberName = 'zen'"

    – Zen
    Nov 9 '10 at 7:24











  • Well, you have provided your whole code. And that's the reason noone has answered - it's too long. Isolate the relevant bits and show only them.

    – Bozho
    Nov 9 '10 at 17:15

















4















I'm trying to execute a query using a PreparedStatement in Java.



I am getting error number 1064 when I try to execute my query (syntax error).



I have tested this in MySQL query browser with substituted values which works fine.



What's wrong with my code?



Here's the relevant code:



String query = "select MemberID, MemberName from members where MemberID = ? or MemberName = ?";
Connection conn = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
PreparedStatement s = conn.prepareStatement(query);
s.setInt(1, 2);
s.setString(2, "zen");
ResultSet rs = s.executeQuery(query);


Here's the exception I'm getting:




com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '? or MemberName
= ?' at line 1











share|improve this question



















  • 1





    give more details about the "error" - exceptions in Java have stacktraces

    – Bozho
    Nov 9 '10 at 6:56











  • Just before the executeQuery gets called I see during debugging that the parameters get substituted into the PreparedStatemet, the query becomes "com.mysql.jdbc.JDBC4PreparedStatement@6e9770a3: select MemberID, MemberName from members where MemberID = 2 or MemberName = 'zen'"

    – Zen
    Nov 9 '10 at 7:24











  • Well, you have provided your whole code. And that's the reason noone has answered - it's too long. Isolate the relevant bits and show only them.

    – Bozho
    Nov 9 '10 at 17:15













4












4








4


1






I'm trying to execute a query using a PreparedStatement in Java.



I am getting error number 1064 when I try to execute my query (syntax error).



I have tested this in MySQL query browser with substituted values which works fine.



What's wrong with my code?



Here's the relevant code:



String query = "select MemberID, MemberName from members where MemberID = ? or MemberName = ?";
Connection conn = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
PreparedStatement s = conn.prepareStatement(query);
s.setInt(1, 2);
s.setString(2, "zen");
ResultSet rs = s.executeQuery(query);


Here's the exception I'm getting:




com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '? or MemberName
= ?' at line 1











share|improve this question
















I'm trying to execute a query using a PreparedStatement in Java.



I am getting error number 1064 when I try to execute my query (syntax error).



I have tested this in MySQL query browser with substituted values which works fine.



What's wrong with my code?



Here's the relevant code:



String query = "select MemberID, MemberName from members where MemberID = ? or MemberName = ?";
Connection conn = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
PreparedStatement s = conn.prepareStatement(query);
s.setInt(1, 2);
s.setString(2, "zen");
ResultSet rs = s.executeQuery(query);


Here's the exception I'm getting:




com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '? or MemberName
= ?' at line 1








java mysql jdbc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 28 '17 at 13:14









Mark Rotteveel

62.6k1479123




62.6k1479123










asked Nov 9 '10 at 6:36









ZenZen

5321810




5321810







  • 1





    give more details about the "error" - exceptions in Java have stacktraces

    – Bozho
    Nov 9 '10 at 6:56











  • Just before the executeQuery gets called I see during debugging that the parameters get substituted into the PreparedStatemet, the query becomes "com.mysql.jdbc.JDBC4PreparedStatement@6e9770a3: select MemberID, MemberName from members where MemberID = 2 or MemberName = 'zen'"

    – Zen
    Nov 9 '10 at 7:24











  • Well, you have provided your whole code. And that's the reason noone has answered - it's too long. Isolate the relevant bits and show only them.

    – Bozho
    Nov 9 '10 at 17:15












  • 1





    give more details about the "error" - exceptions in Java have stacktraces

    – Bozho
    Nov 9 '10 at 6:56











  • Just before the executeQuery gets called I see during debugging that the parameters get substituted into the PreparedStatemet, the query becomes "com.mysql.jdbc.JDBC4PreparedStatement@6e9770a3: select MemberID, MemberName from members where MemberID = 2 or MemberName = 'zen'"

    – Zen
    Nov 9 '10 at 7:24











  • Well, you have provided your whole code. And that's the reason noone has answered - it's too long. Isolate the relevant bits and show only them.

    – Bozho
    Nov 9 '10 at 17:15







1




1





give more details about the "error" - exceptions in Java have stacktraces

– Bozho
Nov 9 '10 at 6:56





give more details about the "error" - exceptions in Java have stacktraces

– Bozho
Nov 9 '10 at 6:56













Just before the executeQuery gets called I see during debugging that the parameters get substituted into the PreparedStatemet, the query becomes "com.mysql.jdbc.JDBC4PreparedStatement@6e9770a3: select MemberID, MemberName from members where MemberID = 2 or MemberName = 'zen'"

– Zen
Nov 9 '10 at 7:24





Just before the executeQuery gets called I see during debugging that the parameters get substituted into the PreparedStatemet, the query becomes "com.mysql.jdbc.JDBC4PreparedStatement@6e9770a3: select MemberID, MemberName from members where MemberID = 2 or MemberName = 'zen'"

– Zen
Nov 9 '10 at 7:24













Well, you have provided your whole code. And that's the reason noone has answered - it's too long. Isolate the relevant bits and show only them.

– Bozho
Nov 9 '10 at 17:15





Well, you have provided your whole code. And that's the reason noone has answered - it's too long. Isolate the relevant bits and show only them.

– Bozho
Nov 9 '10 at 17:15












2 Answers
2






active

oldest

votes


















4















com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
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 '? or MemberName = ?' at line 1




MySQL doesn't understand the meaning of ? in the SQL query. It's indeed invalid SQL syntax. So somehow it's not been replaced by PreparedStatement. And guess what?



PreparedStatement s = conn.prepareStatement(query);
s.setInt(1, intValue);
s.setString(2, strValue);
rs = s.executeQuery(query); // Fail!


You're overridding the prepared query with the original query! You need to call the argumentless PreparedStatement#executeQuery() method instead of Statement#executeQuery(String).



PreparedStatement s = conn.prepareStatement(query);
s.setInt(1, intValue);
s.setString(2, strValue);
rs = s.executeQuery(); // OK!



Unrelated to the problem, your code is leaking resources. The DB will run out of them after several hours and your application will crash. To fix this, you need to follow the JDBC idiom of closing Connection, Statement and ResultSet in the finally block of the try block where they're been acquired. Check the JDBC basic tutorial for more detail.






share|improve this answer























  • This is just for a Homework assignment, and also I truncated most of my code, I do have a method that closes all relevant resources. I tried executeQuery() it works now thanks :P

    – Zen
    Nov 10 '10 at 3:37


















0














If you look at the javadocs for Statement (the superclass of PreparedStatement), the method docs for executeQuery(String) and executeUpdate(String) say this:




Note: This method cannot be called on a PreparedStatement or CallableStatement.




That's what you are doing here: calling executeQuery(String) from Statement on a PreparedStatement object.



Now since the javadocs say that you "cannot" do this, actual behavior you get is unspecified ... and probably JDBC driver dependent. In this case, it appears that the MySQL driver you are using is interpreting this to mean that you are doing the update as a non-prepared statement, so that the ? tokens are NOT interpreted as parameter placeholder. That leads the server-side SQL parser to say "syntax error".



(It would be easier for programmers if a different unchecked exception was thrown by the MySQL driver if you did this; for example UnsupportedOperationException. However, the standard JDBC javadocs don't say what should happen in this situation. It is up to the vendor what their drivers will do.)






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4131092%2fmysqlsyntaxerrorexception-near-when-trying-to-execute-preparedstatement%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4















    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
    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 '? or MemberName = ?' at line 1




    MySQL doesn't understand the meaning of ? in the SQL query. It's indeed invalid SQL syntax. So somehow it's not been replaced by PreparedStatement. And guess what?



    PreparedStatement s = conn.prepareStatement(query);
    s.setInt(1, intValue);
    s.setString(2, strValue);
    rs = s.executeQuery(query); // Fail!


    You're overridding the prepared query with the original query! You need to call the argumentless PreparedStatement#executeQuery() method instead of Statement#executeQuery(String).



    PreparedStatement s = conn.prepareStatement(query);
    s.setInt(1, intValue);
    s.setString(2, strValue);
    rs = s.executeQuery(); // OK!



    Unrelated to the problem, your code is leaking resources. The DB will run out of them after several hours and your application will crash. To fix this, you need to follow the JDBC idiom of closing Connection, Statement and ResultSet in the finally block of the try block where they're been acquired. Check the JDBC basic tutorial for more detail.






    share|improve this answer























    • This is just for a Homework assignment, and also I truncated most of my code, I do have a method that closes all relevant resources. I tried executeQuery() it works now thanks :P

      – Zen
      Nov 10 '10 at 3:37















    4















    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
    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 '? or MemberName = ?' at line 1




    MySQL doesn't understand the meaning of ? in the SQL query. It's indeed invalid SQL syntax. So somehow it's not been replaced by PreparedStatement. And guess what?



    PreparedStatement s = conn.prepareStatement(query);
    s.setInt(1, intValue);
    s.setString(2, strValue);
    rs = s.executeQuery(query); // Fail!


    You're overridding the prepared query with the original query! You need to call the argumentless PreparedStatement#executeQuery() method instead of Statement#executeQuery(String).



    PreparedStatement s = conn.prepareStatement(query);
    s.setInt(1, intValue);
    s.setString(2, strValue);
    rs = s.executeQuery(); // OK!



    Unrelated to the problem, your code is leaking resources. The DB will run out of them after several hours and your application will crash. To fix this, you need to follow the JDBC idiom of closing Connection, Statement and ResultSet in the finally block of the try block where they're been acquired. Check the JDBC basic tutorial for more detail.






    share|improve this answer























    • This is just for a Homework assignment, and also I truncated most of my code, I do have a method that closes all relevant resources. I tried executeQuery() it works now thanks :P

      – Zen
      Nov 10 '10 at 3:37













    4












    4








    4








    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
    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 '? or MemberName = ?' at line 1




    MySQL doesn't understand the meaning of ? in the SQL query. It's indeed invalid SQL syntax. So somehow it's not been replaced by PreparedStatement. And guess what?



    PreparedStatement s = conn.prepareStatement(query);
    s.setInt(1, intValue);
    s.setString(2, strValue);
    rs = s.executeQuery(query); // Fail!


    You're overridding the prepared query with the original query! You need to call the argumentless PreparedStatement#executeQuery() method instead of Statement#executeQuery(String).



    PreparedStatement s = conn.prepareStatement(query);
    s.setInt(1, intValue);
    s.setString(2, strValue);
    rs = s.executeQuery(); // OK!



    Unrelated to the problem, your code is leaking resources. The DB will run out of them after several hours and your application will crash. To fix this, you need to follow the JDBC idiom of closing Connection, Statement and ResultSet in the finally block of the try block where they're been acquired. Check the JDBC basic tutorial for more detail.






    share|improve this answer














    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
    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 '? or MemberName = ?' at line 1




    MySQL doesn't understand the meaning of ? in the SQL query. It's indeed invalid SQL syntax. So somehow it's not been replaced by PreparedStatement. And guess what?



    PreparedStatement s = conn.prepareStatement(query);
    s.setInt(1, intValue);
    s.setString(2, strValue);
    rs = s.executeQuery(query); // Fail!


    You're overridding the prepared query with the original query! You need to call the argumentless PreparedStatement#executeQuery() method instead of Statement#executeQuery(String).



    PreparedStatement s = conn.prepareStatement(query);
    s.setInt(1, intValue);
    s.setString(2, strValue);
    rs = s.executeQuery(); // OK!



    Unrelated to the problem, your code is leaking resources. The DB will run out of them after several hours and your application will crash. To fix this, you need to follow the JDBC idiom of closing Connection, Statement and ResultSet in the finally block of the try block where they're been acquired. Check the JDBC basic tutorial for more detail.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 10 '10 at 2:46









    BalusCBalusC

    864k30431983250




    864k30431983250












    • This is just for a Homework assignment, and also I truncated most of my code, I do have a method that closes all relevant resources. I tried executeQuery() it works now thanks :P

      – Zen
      Nov 10 '10 at 3:37

















    • This is just for a Homework assignment, and also I truncated most of my code, I do have a method that closes all relevant resources. I tried executeQuery() it works now thanks :P

      – Zen
      Nov 10 '10 at 3:37
















    This is just for a Homework assignment, and also I truncated most of my code, I do have a method that closes all relevant resources. I tried executeQuery() it works now thanks :P

    – Zen
    Nov 10 '10 at 3:37





    This is just for a Homework assignment, and also I truncated most of my code, I do have a method that closes all relevant resources. I tried executeQuery() it works now thanks :P

    – Zen
    Nov 10 '10 at 3:37













    0














    If you look at the javadocs for Statement (the superclass of PreparedStatement), the method docs for executeQuery(String) and executeUpdate(String) say this:




    Note: This method cannot be called on a PreparedStatement or CallableStatement.




    That's what you are doing here: calling executeQuery(String) from Statement on a PreparedStatement object.



    Now since the javadocs say that you "cannot" do this, actual behavior you get is unspecified ... and probably JDBC driver dependent. In this case, it appears that the MySQL driver you are using is interpreting this to mean that you are doing the update as a non-prepared statement, so that the ? tokens are NOT interpreted as parameter placeholder. That leads the server-side SQL parser to say "syntax error".



    (It would be easier for programmers if a different unchecked exception was thrown by the MySQL driver if you did this; for example UnsupportedOperationException. However, the standard JDBC javadocs don't say what should happen in this situation. It is up to the vendor what their drivers will do.)






    share|improve this answer



























      0














      If you look at the javadocs for Statement (the superclass of PreparedStatement), the method docs for executeQuery(String) and executeUpdate(String) say this:




      Note: This method cannot be called on a PreparedStatement or CallableStatement.




      That's what you are doing here: calling executeQuery(String) from Statement on a PreparedStatement object.



      Now since the javadocs say that you "cannot" do this, actual behavior you get is unspecified ... and probably JDBC driver dependent. In this case, it appears that the MySQL driver you are using is interpreting this to mean that you are doing the update as a non-prepared statement, so that the ? tokens are NOT interpreted as parameter placeholder. That leads the server-side SQL parser to say "syntax error".



      (It would be easier for programmers if a different unchecked exception was thrown by the MySQL driver if you did this; for example UnsupportedOperationException. However, the standard JDBC javadocs don't say what should happen in this situation. It is up to the vendor what their drivers will do.)






      share|improve this answer

























        0












        0








        0







        If you look at the javadocs for Statement (the superclass of PreparedStatement), the method docs for executeQuery(String) and executeUpdate(String) say this:




        Note: This method cannot be called on a PreparedStatement or CallableStatement.




        That's what you are doing here: calling executeQuery(String) from Statement on a PreparedStatement object.



        Now since the javadocs say that you "cannot" do this, actual behavior you get is unspecified ... and probably JDBC driver dependent. In this case, it appears that the MySQL driver you are using is interpreting this to mean that you are doing the update as a non-prepared statement, so that the ? tokens are NOT interpreted as parameter placeholder. That leads the server-side SQL parser to say "syntax error".



        (It would be easier for programmers if a different unchecked exception was thrown by the MySQL driver if you did this; for example UnsupportedOperationException. However, the standard JDBC javadocs don't say what should happen in this situation. It is up to the vendor what their drivers will do.)






        share|improve this answer













        If you look at the javadocs for Statement (the superclass of PreparedStatement), the method docs for executeQuery(String) and executeUpdate(String) say this:




        Note: This method cannot be called on a PreparedStatement or CallableStatement.




        That's what you are doing here: calling executeQuery(String) from Statement on a PreparedStatement object.



        Now since the javadocs say that you "cannot" do this, actual behavior you get is unspecified ... and probably JDBC driver dependent. In this case, it appears that the MySQL driver you are using is interpreting this to mean that you are doing the update as a non-prepared statement, so that the ? tokens are NOT interpreted as parameter placeholder. That leads the server-side SQL parser to say "syntax error".



        (It would be easier for programmers if a different unchecked exception was thrown by the MySQL driver if you did this; for example UnsupportedOperationException. However, the standard JDBC javadocs don't say what should happen in this situation. It is up to the vendor what their drivers will do.)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 23 at 2:25









        Stephen CStephen C

        530k72591950




        530k72591950



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4131092%2fmysqlsyntaxerrorexception-near-when-trying-to-execute-preparedstatement%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript