gpt4 book ai didi

sql-server-2005 - SQL Server 2005 到 2012 com.microsoft.sqlserver.jdbc.SQLServerException : Implicit conversion from data type varbinary to datetime2 is not allowed

转载 作者:行者123 更新时间:2023-12-02 00:56:16 24 4
gpt4 key购买 nike

我们正在从 SQL Server 2005 迁移到 2012。其中一项功能失败并出现此错误

com.microsoft.sqlserver.jdbc.SQLServerException: Implicit conversion from data type varbinary to datetime2 is not allowed. Use the CONVERT function to run this query.

我们使用 SQLJDBC 驱动程序 3.0 与 SQL Server 2012 进行通信。当我们尝试将 NULL 值插入 DATETIME 列(可为空)时,我看到这个问题正在发生。但在 2005 年仍然有效。感谢任何对此问题的帮助。

这是一个简单的 INSERT 语句,使用 MyBatis ORM 从 Java 到 SQL server 2012 失败:

Insert into temp_test (date1, name, date2) values ('2010-10-10 00:00:00.0','test',null) 

当我们从我们的应用程序(使用 SQL JDBC 驱动程序)中尝试时,此插入失败...但是相同的代码库在 SQL 2005 中可以正常工作。

最佳答案

我刚刚在 MyBatis 和 SQL Server 2012 中尝试插入 DATETIME2 列可能为空的地方时遇到了这个错误。我的问题的解决方案是按照 MyBatis 文档中的规定在我的映射器文件中指定 JDBC 类型。

发件人:http://www.mybatis.org/mybatis-3/sqlmap-xml.html#Parameters

The JDBC Type is required by JDBC for all nullable columns, if null is passed as a value. You can investigate this yourself by reading the JavaDocs for the PreparedStatement.setNull() method.

在映射器文件中的插入语句中,date2 列的值将添加“jdbctype = TIMESTAMP”,如下所示:

<insert id="testInsert" parameterType="com.example.object">
INSERT INTO tempt_test
(date1, name, date2)
VALUES
(#{date1}, #{name}, #{date2, jdbcType = TIMESTAMP})
</insert>

关于sql-server-2005 - SQL Server 2005 到 2012 com.microsoft.sqlserver.jdbc.SQLServerException : Implicit conversion from data type varbinary to datetime2 is not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34797629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com