0

i got issue when i go to Insert value to DB (do nothing). before that i do select table to get last id, and it worked. Here's my Code:

IDBManager dbManager = getParentExtension().getParentZone().getDBManager();
    Connection connection = null;   

    int idRoom = params.getInt("idRoom");
    String betsmall = params.getUtfString("betsmall");
    int Uid  = params.getInt("recid");

    try{
        connection = dbManager.getConnection();
        PreparedStatement stmt = connection.prepareStatement("SELECT id_game from detail_game ORDER BY id_game DESC LIMIT 1");

        ResultSet res = stmt.executeQuery();
        if (!res.first())
        {
            trace("bla bla");
        }

        int id = res.getInt("id_game");
       trace (id);
    //  **till here there is no problem, i can get id from select query

      PreparedStatement stmts = connection.prepareStatement("INSERT INTO detil_bet (id_user, id_room, id_bet, bettype) VALUES (?, ?, ?, ? ");
      stmts.setInt(1, Uid);
      stmts.setInt(2, idRoom);
      stmts.setInt(3, id);
      stmts.setString(4, betsmall);
      stmts.executeUpdate();

    }
}

Here's the problem, insert do nothing.

2
  • 2
    You're missing ) in values part. Commented Sep 1, 2016 at 8:01
  • 1
    In the case there is a ) missing you should get an exception?! Commented Sep 1, 2016 at 8:02

2 Answers 2

1
PreparedStatement stmts = connection.prepareStatement("INSERT INTO detil_bet (id_user, id_room, id_bet, bettype) VALUES (?, ?, ?, ? ");

Looks like you need some end parentheses in "VALUES".

A catch block to print stack trace would have told you the issue here as well. I'm not the best SQL guy, I always use this to check my SQL syntax as well to double check if I've done everything right.

Sign up to request clarification or add additional context in comments.

Comments

0

your connection seems not auto commit. Try to add

stmts.commit();

after "stmts.executeUpdate();".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.