DDL with parameters in JdbcTemplate
Hi, I can't figure out how to execute DDL with parameters using some of the JdbcTemplate family classes. Specifically I am trying to create a user in oracle database and neither of these works:
Code:
@Test
public void testJdbcTemplate() {
NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("username", "myuser");
params.put("password", "mypassword");
jdbcTemplate.update("CREATE USER &username IDENTIFIED BY &password", params);
}
@Test
public void testJdbcTemplate2() {
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
jdbcTemplate.update("CREATE USER ? IDENTIFIED BY ?", "myuser", "mypassword");
}
The result is always the same:
Code:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [CREATE USER ? IDENTIFIED BY ?]; nested exception is java.sql.SQLException: ORA-01935: missing user or role name
Also notice that in PL/SQL developer
Code:
create user myuser identified by mypassword
works great, whereas
Code:
create user 'myuser' identified by 'mypassword'
gives ORA-01935.
Is there a better way to do this, other than manually replacing placeholders in SQL?