Note that there are some explanatory texts on larger screens.

plurals
  1. POError is Sql syntax
    primarykey
    data
    text
    <p>I am getting SQL syntax error in the following code snippet. What is the problem here? I am unable to figure it out. Please help.</p> <pre><code>String selectSQL = "SELECT * FROM cost_info where `date` &gt; ? and `date` &lt; ? order by `date`"; PreparedStatement preparedStatement = conn.prepareStatement(selectSQL); java.sql.Date sqlFromDate = java.sql.Date.valueOf(from_date); java.sql.Date sqlEndDate = java.sql.Date.valueOf(end_date); preparedStatement.setDate(1, sqlFromDate ); preparedStatement.setDate(2, sqlEndDate ); rs = preparedStatement.executeQuery(selectSQL); </code></pre> <p>I am using MySQL. Error is:</p> <pre><code>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 '? and `date` &lt; ? order by `date`' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.Util.getInstance(Util.java:386) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2569) at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1521) at com.source.viralmo.rms.CostDisplay.initialize(CostDisplay.java:77) at com.source.viralmo.rms.CostDisplay.&lt;init&gt;(CostDisplay.java:34) at com.source.viralmo.rms.AdminPage.actionPerformed(AdminPage.java:141) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload