title: Java MySQL how to select all elemnts with id greater than particular
body: <p>I have a database like this:</p>
  
  <p>id----name----place</p>
  
  <p>1----George -----some</p>
  
  <p>2----John ------some</p>
  
  <p>3----Stefi------hawaii</p>
  
  <p>And I have a variable that I get from servlet which is the value we want to compare with. let's say it's idOwn=1, so we want to select everything with id greater then 1, in this case John and Stefi. Here's what I did till now but it says there is syntax problem.</p>
  
  <pre><code>else if (idOwn != 0) {
          sql = "SELECT * FROM posts WHERE id&gt;? LIMIT 25";
  
          try {
              stmt = (PreparedStatement) GetConnection.buildConnection()
                      .prepareStatement(sql);
              stmt.setLong(1, idOwn);
              st = stmt.executeQuery();
              while (st.next()) {
                  list.add(new PostBuilder()
                          .setName(st.getString("name"))
                          .setTime(st.getTimestamp("time"))
                          .setMessage(st.getString("message"))
                          .setId(st.getLong("id"))
                          .setUserId(st.getLong("userID"))
                          .setComments(CommentRegistry.getInstance().fetchComments(idOwn)).build());
                 return list;
              }
  </code></pre>
  
  <p>Thank you in advance :)
  Since you asked here a StackTrace </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 '?' at line 1
  at sun.reflect.GeneratedConstructorAccessor14.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:408)
  at com.mysql.jdbc.Util.getInstance(Util.java:383)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1062)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158)
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
  at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2834)
  at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2783)
  at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1569)
  at com.kasapin40.social.comments.CommentRegistry.fetchComments(CommentRegistry.java:46)
  at com.kasapin40.social.posts.PostRegistry.getPostList(PostRegistry.java:87)
  at com.kasapin40.social.servlet.FetchPosts.doGet(FetchPosts.java:36)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at com.kasapin40.social.filter.LoginFilter.doFilter(LoginFilter.java:33)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
  at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:534)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
  at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>