0
votes

here is the thing

ps = conn.prepareStatement("INSERT INTO goods_country(goodsId,goodsCountry) VALUES (?,?)");
ps.setInt(1, this.returnId());
ps.setString(2, goodsCountry);
int exe = ps.executeUpdate();

Im sure that this.returnId() and goodsCountry has value, when run this code that occur this error

java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3321) at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3306) at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3345) at com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:3296) at com.backend.model.MoviesBeanBO.inserCountry(MoviesBeanBO.java:67) at com.backend.controller.MovieOnBoard.doPost(MovieOnBoard.java:71) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:25)

can't figure it out what happened, if somebody can help ,I would be very appreciate. thx!

1
Can't see an error in your code. Which version of the jdbc driver are you using? Maybe you could verify if this error occors if you use another driver versionZeusNet
Try to remove space between values and (?,?)prem30488

1 Answers

0
votes

Try to remove space between values and question mark

    ps = conn.prepareStatement("INSERT INTO goods_country(goodsId,goodsCountry) VALUES(?,?)");
    ps.setInt(1, this.returnId());
    ps.setString(2, goodsCountry);
    int exe = ps.executeUpdate();

or the driver jar file needs to be checked.