[英]How to create a function in MySQL from an SQL script, JDBC or Spring JdbcTemplate?
[英]How to CREATE USER in MySQL from JdbcTemplate?
我正在嘗試使用更新方法從JdbcTemplate
在MySql
為用戶創建帳戶。 我的查詢像這樣
String sqlStatement = "CREATE USER ?@? IDENTIFIED BY ?";
Object[] values = new Object[3];
-
--
我將所需的值放在Value []中,例如用戶名,本地主機和密碼。 而且我敢肯定,我會在value []中放入值。
我正在執行此查詢
jdbcTemplate.update(sqlStatement, values);
它給了我這個錯誤錯誤。
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [CREATE USER ?@? IDENTIFIED BY ?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:95) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:909) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:970) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:980) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
我已將所有權限授予我在連接中使用的用戶。為進行確認,我可以從Workbench使用相同的命令創建用戶。
在我的連接URL中,我正在使用類似這樣的PC IP地址: jdbc:mysql://10.35.34.169:3306/mydb
我猜不是使用jdbcTemplate.update(...),而是使用jdbcTemplate.execute(...)並將sql字符串傳遞為
創建用戶“ abdul123”標識的用戶abdul123
我
jdbcTemplate.execute("CREATE USER abdul123 IDENTIFIED BY 'abdul123'");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.