Preparedstatement is not working

Asked

Viewed 261 times

0

Code I’m using

PreparedStatement i = conexao.prepareStatement("INSERT INTO teste VALUES (player='teste', level_1=0, level_2=0, level_3=0, level_4=0, level_5=0, level_6=0, level_7=0, level_8=0, level_9=0, level_10=0)");
i.executeUpdate();

Table structure. inserir a descrição da imagem aqui

It just happens with the Insert into, I’ve used this same code to create the table and no problem, this simply does not insert, what is the problem?

Don’t make any mistakes, nothing, just don’t insert.

  • What went wrong? Does it give a Sqlexception? Does it do anything? Does it insert anything other than what it should insert? Did he manage to connect to the database? I don’t see anything wrong with the little code you provided, maybe the problem is somewhere else.

  • Name the columns tbm and not only the value.

  • @rray But he put. See the SQL statement.

  • @Victorstafusa, I understood is that update format Insert, by the image it seems that all values are in a column.

  • @rray "this simply does not insert"

  • If you copy the Insert and test directly in the bank it works? or any error?

  • @rray works perfectly.

  • 1

    Using mysql? using transfer? auto commit is on?

  • 1

    yes, I don’t know what that is, and the auto commit I left false.

  • 2

    does a test, leaves auto commit true, ai whenever you send a query in the bank will be applied on time. Already with auto commit false you need to tell the bank to perform the operation (Insert, update, delete) successfully use commit and for failure rollback.

  • @rray left true and worked perfectly. Thank you.

  • This question is very superficial, more information is needed.

  • @Delfino has already been solved.

  • @Leonardosnt, I understand, but it would be interesting to adjust the question, keeping the site organized. Making it easier for others to gain access to information.

Show 9 more comments

2 answers

8


Fur comments it was possible to discover that the problem was not your code but the configuration of the database, the autocommit was off (so no Exception was released), so write instructions (INSERT, UPDATE, DELETE) are only applied to the database after a call commit for success or rollback to fail, without the call of either of these two commands the query is in a 'draft' state only who performed the operation see the result.

Recommended reading:

How to enable autocommit by Workbench or phpmyadmin

What are the advantages and disadvantages of using transaction explicitly

Mysql Transaction When? How? Why?

What is a Mysql Transaction for?

  • Thanks, I’ll read on that later.

0

Try to do so:

PreparedStatement i = conexao.prepareStatement("INSERT INTO teste (player, level_1, level_2, level_3, level_4, level_5, level_6, level_7, level_8, level_9, level_10) VALUES ('teste', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)");
i.executeUpdate();
  • Same thing, didn’t insert.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.