我正在使用preparedStatement,并且我有java.sql.SQLException错误
query = "INSERT INTO instdb (" +
"id," +
"name," +
"username," +
"descr," +
"tel," +
"vk," +
"ownerId," +
"query," +
"postId," +
"parametr) VALUES" +
"(?,?,?,?,?,?,?,?,?,?)";
stmt = con.prepareStatement(query);
stmt.setInt(1, maxid);
stmt.setString(2,user.getFull_name());
stmt.setString(3,username);
stmt.setString(4,caption);
stmt.setString(5,longestTel);
stmt.setString(6,vk);
stmt.setString(7,ownerId);
stmt.setString(8,addons.get(j));
stmt.setString(9,postId);
stmt.setString(10,param);
并且发生stmt.setInt(1, maxid);
错误
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
编辑 1
我替换 stmt = con.prepareStatement(query);
并出现新错误:
java.sql.SQLSyntaxErrorException: 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 '?,?,?,?,?,?,?,?,?,?)'
附注 这对我没有帮助stackoverflow
最佳答案
您是否忘记初始化stm
?
stm = con.prepareStatement(query);
其中 con
是您的 Connection
对象。
关于java - MySQL插入数据时出现 'java.sql.SQLException'错误如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55305595/