无法使用 JTDS 1.3.1 执行 SQL 服务器脚本
Can't execute SQL Server script with JTDS 1.3.1
同志们,我需要帮助!我无法使用 JTDS 驱动程序版本 1.3.1 执行 SQL 服务器脚本。详情如下。
我试图删除一些 SQL 脚本行,但无济于事。
SQL 脚本:
USE [SomeScheme]
GO
DECLARE @ID int
, @Guid nvarchar(50)
, @Name nvarchar(250)
, @Caption nvarchar(250)
, @Description nvarchar(max)
SET @Description = NULL;
SET @Guid = 'EAID_4076F221_3910_4480_B49A_09621E214249';
SET @Name = 'datetime';
SET @Caption = 'datetime';
IF EXISTS(SELECT [Guid] FROM rdf.SimplePropertyTypes WHERE [Guid] = @Guid)
BEGIN
SET @ID = (SELECT ID FROM rdf.SimplePropertyTypes WHERE [Guid]=@Guid)
UPDATE rdf.SimplePropertyTypes
SET Name = @Name
, Caption = @Caption
, [Description] = @Description
WHERE [Guid]=@Guid
END
ELSE
BEGIN
SET @ID = ISNULL((SELECT MAX(ID) FROM rdf.SimplePropertyTypes),0) + 1000
INSERT INTO rdf.SimplePropertyTypes(ID, [Guid], Name, Caption, [Description]) VALUES
(@ID, @Guid, @Name, @Caption, @Description);
END
SET @Description = NULL
Java代码:
try (final Connection connection = sourceDataSource.getConnection();
final CallableStatement callableStatement = connection.prepareCall(sql)) {
callableStatement.executeUpdate();
}
异常堆栈跟踪:
Caused by: java.sql.SQLException: Invalid JDBC escape syntax at line position 68 '=' character expected.
at net.sourceforge.jtds.jdbc.SQLParser.mustbe(SQLParser.java:412)
at net.sourceforge.jtds.jdbc.SQLParser.callEscape(SQLParser.java:554)
at net.sourceforge.jtds.jdbc.SQLParser.escape(SQLParser.java:1009)
at net.sourceforge.jtds.jdbc.SQLParser.parse(SQLParser.java:1178)
at net.sourceforge.jtds.jdbc.SQLParser.parse(SQLParser.java:165)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.<init>(JtdsPreparedStatement.java:111)
at net.sourceforge.jtds.jdbc.JtdsCallableStatement.<init>(JtdsCallableStatement.java:70)
at net.sourceforge.jtds.jdbc.JtdsConnection.prepareCall(JtdsConnection.java:2426)
at net.sourceforge.jtds.jdbc.JtdsConnection.prepareCall(JtdsConnection.java:2412)
at org.apache.commons.dbcp.DelegatingConnection.prepareCall(DelegatingConnection.java:308)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareCall(PoolingDataSource.java:303)
驱动程序: JTDS 1.3.1
需要帮助!
准备好的语句中不允许GO,因此答案是:
try (final Connection connection = sourceDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(sql.replaceAll(" GO\n", " "))) {
preparedStatement.executeUpdate();
}
同志们,我需要帮助!我无法使用 JTDS 驱动程序版本 1.3.1 执行 SQL 服务器脚本。详情如下。
我试图删除一些 SQL 脚本行,但无济于事。
SQL 脚本:
USE [SomeScheme]
GO
DECLARE @ID int
, @Guid nvarchar(50)
, @Name nvarchar(250)
, @Caption nvarchar(250)
, @Description nvarchar(max)
SET @Description = NULL;
SET @Guid = 'EAID_4076F221_3910_4480_B49A_09621E214249';
SET @Name = 'datetime';
SET @Caption = 'datetime';
IF EXISTS(SELECT [Guid] FROM rdf.SimplePropertyTypes WHERE [Guid] = @Guid)
BEGIN
SET @ID = (SELECT ID FROM rdf.SimplePropertyTypes WHERE [Guid]=@Guid)
UPDATE rdf.SimplePropertyTypes
SET Name = @Name
, Caption = @Caption
, [Description] = @Description
WHERE [Guid]=@Guid
END
ELSE
BEGIN
SET @ID = ISNULL((SELECT MAX(ID) FROM rdf.SimplePropertyTypes),0) + 1000
INSERT INTO rdf.SimplePropertyTypes(ID, [Guid], Name, Caption, [Description]) VALUES
(@ID, @Guid, @Name, @Caption, @Description);
END
SET @Description = NULL
Java代码:
try (final Connection connection = sourceDataSource.getConnection();
final CallableStatement callableStatement = connection.prepareCall(sql)) {
callableStatement.executeUpdate();
}
异常堆栈跟踪:
Caused by: java.sql.SQLException: Invalid JDBC escape syntax at line position 68 '=' character expected.
at net.sourceforge.jtds.jdbc.SQLParser.mustbe(SQLParser.java:412)
at net.sourceforge.jtds.jdbc.SQLParser.callEscape(SQLParser.java:554)
at net.sourceforge.jtds.jdbc.SQLParser.escape(SQLParser.java:1009)
at net.sourceforge.jtds.jdbc.SQLParser.parse(SQLParser.java:1178)
at net.sourceforge.jtds.jdbc.SQLParser.parse(SQLParser.java:165)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.<init>(JtdsPreparedStatement.java:111)
at net.sourceforge.jtds.jdbc.JtdsCallableStatement.<init>(JtdsCallableStatement.java:70)
at net.sourceforge.jtds.jdbc.JtdsConnection.prepareCall(JtdsConnection.java:2426)
at net.sourceforge.jtds.jdbc.JtdsConnection.prepareCall(JtdsConnection.java:2412)
at org.apache.commons.dbcp.DelegatingConnection.prepareCall(DelegatingConnection.java:308)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareCall(PoolingDataSource.java:303)
驱动程序: JTDS 1.3.1
需要帮助!
准备好的语句中不允许GO,因此答案是:
try (final Connection connection = sourceDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(sql.replaceAll(" GO\n", " "))) {
preparedStatement.executeUpdate();
}