"@ P0"附近的语法不正确.在MSSQL中创建和删除登录名时出现异常 [英] Incorrect syntax near '@P0'. exception when create and drop Login in MSSQL
问题描述
我正在尝试使用Microsoft JDBC驱动程序创建一个登录名并将其删除.
I'm trying to create a Login and drop it using using Microsoft JDBC Driver.
CREATE LOGIN ? WITH PASSWORD = 'password'
和
DROP LOGIN ?
但是在两种情况下,我都会遇到以下异常情况.
But I'm getting following exception in both cases.
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P0'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:332)
at org.wso2.carbon.rssmanager.core.internal.manager.MSSQLRSSManager.attachUserToDatabase(MSSQLRSSManager.java:512)
... 57 more
我在SO中发现了类似的问题,但是找不到确切的解决方案.
I found similar questions in SO, but couldn't find an exact solution.
请咨询.
谢谢, 巴提亚(Bhathiya)
Thanks, Bhathiya
[更新]
这是我的代码段.
String sql = "CREATE LOGIN ? WITH PASSWORD = 'abc'";
stmt = conn.prepareStatement(sql);
stmt.setString(1, qualifiedUsername);
stmt.execute();
推荐答案
您不能使用?在drop login
语句中(就像在拖放表中一样,您不能编写drop table ?
-那天我正面临着同样的问题!),您必须以旧的方式构建带有字符串连接的语句.
You can't use ? in drop login
statement (like in drop table, you cant write drop table ?
- I'm facing the same problem just in that days!), you have to build statement with string concatenation in old fashion way.
这篇关于"@ P0"附近的语法不正确.在MSSQL中创建和删除登录名时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!