1

i have a table "queue_in_progress" whose structure is like the following :

enter image description here

I want to update the DATE_TIME_TOKEN_TAKEN , CE_PK , Service_status of the table . For this , I have the following code :

    String sqlQuery = "UPDATE queue_in_progress\n"  +
                 "SET CE_PK="+ce_pk+" ,SERVICE_STATUS=1 \n"  +
                 "WHERE CATEGORY_PK="+Category_PK+" AND TOKEN_NO="+ Token_PK+" "
                    + " AND SERVICE_COUNTER="+service_counter+" AND SERVICE_CENTER_PK="+service_center+" ;";

java.util.Date utilDate = new Date();  // Convert it to java.sql.Date
java.sql.Date date = new java.sql.Date(utilDate.getTime());

PreparedStatement stmt = con.prepareStatement(sqlQuery);
                    stmt.setDate(1, date);
                    success = stmt.executeUpdate();

 But the success flag is returning -1 and the table is not updated . What is the problem ? What can I do to fix this problem ? 
4
  • 1
    I don't see a bind parameter in your query. Commented Nov 1, 2014 at 6:36
  • What do you want to mean by this statement ? Commented Nov 1, 2014 at 6:39
  • What would stmt.setDate(1, date); statement do? And I would also suggest you to review the query. Commented Nov 1, 2014 at 6:40
  • Can u do System.out.println(sqlQuery) before prepared statement and show us the result!! If u don't mind!! Commented Nov 1, 2014 at 7:13

2 Answers 2

1

I don't see DATE_TIME_TOKEN_TAKEN=? in your query (the bind parameter), I think you wanted

String sqlQuery = "UPDATE queue_in_progress SET DATE_TIME_TOKEN_TAKEN=?, "
        + "CE_PK=" + ce_pk
        + ", SERVICE_STATUS=1 WHERE CATEGORY_PK="
        + Category_PK
        + " AND TOKEN_NO="
        + Token_PK
        + " AND SERVICE_COUNTER="
        + service_counter + " AND SERVICE_CENTER_PK=" + service_center;
Sign up to request clarification or add additional context in comments.

4 Comments

I want that "DATE_TIME_TOKEN_TAKEN" field should be filled with current system time . What can I do to do that ?
stmt.setDate(1, new java.sql.Date()); or you modify your query (but the precise syntax depends on your database).
stmt.setDate(1, new java.sql.Date()) exists in my code . So where is the problem ?
Start over. Is the row now updating? If so, it is getting the current system date.
0

OR if you want DATE_TIME_TOKEN_TAKEN to ALWAYS hold Current Time value, you can Set it on your Database side, no need to set it in your code.

ALTER TABLE queue_in_progress
MODIFY DATE_TIME_TOKEN_TAKEN DEFAULT CURRENT_TIMESTAMP;

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.