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:
The result is always the same: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"); }
Also notice that in PL/SQL developerCode: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
works great, whereasCode:create user myuser identified by mypassword
gives ORA-01935.Code:create user 'myuser' identified by 'mypassword'
Is there a better way to do this, other than manually replacing placeholders in SQL?


Reply With Quote
