0

I have a Spring project and when i create a register user on table i have to create a database user too.

Now i have:

user = userRepository.save(user);

The command is:

CREATE USER 'username' IDENTIFIED BY 'password';

Is it possible?

1 Answer 1

1

You can do it like below:

//UserService

@Autowired
private JdbcTemplate jdbcTemplate;

...
user = userRepository.save(user);
jdbcTemplate.execute("CREATE USER \'username\' IDENTIFIED BY \'password\'");

Note that your datasource user defined in application properties should have suitable privileges to create user and etc.

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

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.