Java Prepared statement not executing

懵懂的女人 提交于 2019-12-02 06:52:11

You should invoke the method executeUpdate() on the statement object.

Also, I don't see any call to commit the data, any transaction handling. It's fine if you skipped that piece of code for the purpose of this question; otherwise it's quite an important step ( commit if all goes well, rollback for exception scenarios)

Use executeUpdate for database write operations:

preparedStmt.executeUpdate();

Answer: The database ID was not set to auto increment. For some reason this does not allow you to then insert data to table. Thanks to ChadNC for pointing this out.

Also, why st = con.createStatement();?

And why do you have a leading space in your query?

String query = " INSERT INTO user_information (name, email, country, password)" 
                 + " VALUES (?, ?, ?, ?)";

This leading space may or may not matter...

Lastly, you should be closing your connection when you're through with it, using try-with-resources or a finally block.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!