Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a query script that is an update sql query having regex_replace to update a specific string to the desired string in db. I have used prepared statement of Java to run this query in my script. Something like this:

String SQL="UPDATE query where created >= ?  and created < ?";
    PreparedStatement stmt = conn.prepareStatement(SQL);
    conn.setAutoCommit(false);
    stmt.setDate(1, new java.sql.Date(datecreated.getTime()));
    stmt.setDate(2, new java.sql.Date(datecreatedTill.getTime()));
    stmt.addBatch();
    System.out.println("Script start time: "+ new java.util.Date());
    result = stmt.executeBatch();
    conn.commit();

So, I have the following questions now:

1. Is it the correct way to use prepared statement to optimize the update I intend to use?
2. Also, I read that preparedstatement basically combines all the queries into one or optimize multiple sql queries being passed to the db. So, i don't know how this regex_replce update query will get optimised as it will be just one sql query running on multiple records.
3. Please suggest if this is not a correct approach then if there is a better approach I can use

What I have tried:

I have tried to look over internet but optimising update with regex_replace is nowhere on the internet.
Posted
Comments
CHill60 14-Sep-22 4:25am    
You haven't said what you are going to update on table query
Rohit Dubey Sep2022 14-Sep-22 12:50pm    
I am updating a regex string in column value with something.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900