1

I have a list of insert sql strings throw mysqldump. E.g.

INSERT INTO table (id, name) VALUES (1, 'wow');
INSERT INTO table (id, name) VALUES (2, 'yeah');

I want to import this sql to another service, and add 10 to each sql's id. I know PreparedStatement in java.sql can set parameter to sql like this:

INSERT INTO table (id, name) VALUES (?, ?);

But how to analyze an existing sql, get and replace a parameter in Java?

5
  • INSERT INTO table (id, name) VALUES (10 + ?, ?); ? Commented Mar 11, 2020 at 10:11
  • update table set id = id +10 Commented Mar 11, 2020 at 10:12
  • These SQL are generated through mysqldump. I don't have the parameters of each field. Commented Mar 11, 2020 at 10:15
  • See JSqlParser Commented Mar 11, 2020 at 10:22
  • you can use str.replace('VALUES (', 'VALUES ( 10 + ') Commented Mar 11, 2020 at 10:25

1 Answer 1

1

I'm not quite sure how your strings are stored, but as a string replacement, you can do:

replace(sql_strings, ", '", " + 10, '")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. My sql strings will be more complicated. Using str.replace may not work. I think I should change the way to export my data.

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.