Import required packages import *; public class JDBCExample { // JDBC driver name and database URL static final String JDBC_DRIVER = "com.Driver"; static final String DB_URL = "jdbc:mysql://localhost/STUDENTS"; // Database credentials static final String USER = "username"; static final String PASS = "password"; public static void main(String[] args) { Connection conn = null; Statement stmt = null; try{ //STEP 2: Register JDBC driver Name("com.

updating a select statement to update-88

As long as you do this in one transaction, and use the for update clause, you will be the only one that can modify the record. It's been a while since I read them and also a while since I used Oracle, but he does describe transactions and use of FOR UPDATE.

When you use the for update clause, Oracle will tak e are that you will get a write lock on the data. But they can't do a select for update, and they can't alter the record until you end the transaction.

You can Google for 'Pessimistic locking' to get more info on this (troublesome) topic.

Type ----------------------------------------- -------- ---------------------------- MSG_ID NOT NULL NUMBER(20) DNIS NUMBER(10) SHORT_MESSAGE VARCHAR2(200) MOBILE_NUMBER NUMBER(10) RECEIVE_TIME TIMESTAMP(6) READ_FLAG NUMBER(2) Now i want to read 10 messages at particular interval, Lets say i am reading 10 messages using select statement and when to fire the select statement i am deciding through java scheduler.

but while i am reading a messages from the table using select statement i want to update the READ_FLAG value at the same time instance. PLUS some other application will be continuously performing insert in SMS_INBOUND table. Thanks & Regards, Jigar Naik This might work: Open transaction Get list of msg ids you want to handle for each of these MSG_IDs: select .... FOR UPDATE; (if you have a unique index on MSG_ID, this allows Oracle to only lock that row. ; Commit transactionwhat id i don't use FOR UPDATE ?

so use of the flag is to keep track on how many messages i have read using select statement for further processing. Else this can result in a page lock - or worse) You now have unique update access to that row, as long as your transaction lasts. Because i am getting the primary key while firing select statement.

and even if i use for update there's going to be two transaction on database one is SELECT and the other is UPDATE.

What if I use simple Select statement to get the record and simple update statement bases on the primary key to update the flag column ?

Hi Jigar Naik, Write a procedure consisting of the following steps.

Step 1 : First select the records according to the requirement.

Step 2 : Pass the unique value (Primary Key Column) of above selected records as an input to update statement to update the flag.