iBATIS.NET Tips & Tricks(2) : 将image列设置为null值时遇到的Operand type clash异常。

简介:

有时我们需要将图片存储在数据库中,此时可将列的类型设置为image。在对该列进行更新(Insert, Update)时,如果要设置的值为null,可能会有问题,考虑这条语句:

< insert  id ="Category_Insert"  parameterClass ="Category" >
INSERT INTO Categories (CategoryName,Description,Picture)
VALUES (#CategoryName#,#Description#,#Picture#)
</ insert >

如果Category类的Picture属性为null,那么在插入数据会引发异常,其信息为:

Operand type clash: nvarchar is incompatible with image.

奇怪,我什么时候插入nvarchar值的?其原因是,如果没有设置参数的类型,iBATIS会自动解析参数的类型,将具有null值的参数类型设置为varchar,因此引发上述异常,解决办法是显式指定该列的类型。

一是使用内联参数:

< insert  id ="Category_Insert"  parameterClass ="Category" >
INSERT INTO Categories (CategoryName,Description,Picture)
VALUES (#CategoryName#,#Description#,#Picture:image#)
</ insert >

二是使用外部参数:

< insert  id ="Category_Insert"  parameterMap ="Para_Category_Insert" >
    INSERT INTO [Categories] ([CategoryName],[Description],[Picture])
    VALUES (?, ?, ?)
</ insert >

< parameterMap  id ="Para_Category_Insert"  class ="Category" >
    
< parameter  property ="CategoryName"  column ="CategoryName"   />
    
< parameter  property ="Description"  column ="Description"   />
    
< parameter  property ="Picture"  column ="Picture"  dbType="image"   />
</ parameterMap > 

将Picture对应的列指定为image类型,这样就不会有问题了。


本文转自一个程序员的自省博客园博客,原文链接:http://www.cnblogs.com/anderslly/archive/2007/11/02/ibatisnullimage.html,如需转载请自行联系原作者。

目录
相关文章
【Azure 事件中心】向Event Hub发送数据异常 : partitionId[null]: Sending messages timed out
【Azure 事件中心】向Event Hub发送数据异常 : partitionId[null]: Sending messages timed out
274 0
【bug记录】旋转链表与力扣报错:member access within null pointer of type ‘struct ListNode‘
【bug记录】旋转链表与力扣报错:member access within null pointer of type ‘struct ListNode‘
473 0
|
网络协议 Java Apache
【Java】已解决java.net.HttpRetryException异常
【Java】已解决java.net.HttpRetryException异常
748 0
|
网络协议 Java
【Java】已解决java.net.UnknownHostException异常
【Java】已解决java.net.UnknownHostException异常
5534 0
|
Shell
Image provider: AssetImage(bundle: null, name: “assets/images/hot.png”) Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#9d9f7(), name: “assets/images/hot.png”, scale: 1) 图像无法加载,并且其他图标图像也出错的解决方案-优雅草卓伊凡
Image provider: AssetImage(bundle: null, name: “assets/images/hot.png”) Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#9d9f7(), name: “assets/images/hot.png”, scale: 1) 图像无法加载,并且其他图标图像也出错的解决方案-优雅草卓伊凡
479 12
|
开发框架 安全 .NET
【Azure Developer】.NET Aspire 项目本地调试遇 Grpc.Core.RpcException 异常( Error starting gRPC call ... )
Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot
627 12
|
机器学习/深度学习 编解码 算法
【小样本图像分割-4】nnU-Net: Self-adapting Framework for U-Net-Based Medical Image Segmentation
《nnU-Net: 自适应框架用于基于U-Net的医学图像分割》是一篇2018年的论文,发表在Nature上。该研究提出了一种自适应的医学图像分割框架nnU-Net,能够自动调整模型的超参数以适应不同的数据集。通过2D和3D U-Net及级联U-Net的组合,nnU-Net在10个医学分割数据集上取得了卓越的性能,无需手动调整。该方法强调数据增强、预处理和训练策略等技巧,为医学图像分割提供了一个强大的解决方案。
1211 0
【小样本图像分割-4】nnU-Net: Self-adapting Framework for U-Net-Based Medical Image Segmentation
|
缓存 NoSQL Java
【Azure Redis 缓存 Azure Cache For Redis】Redis出现 java.net.SocketTimeoutException: Read timed out 异常
【Azure Redis 缓存 Azure Cache For Redis】Redis出现 java.net.SocketTimeoutException: Read timed out 异常
438 5
|
缓存 NoSQL 网络协议
【Azure Redis 缓存】Redisson 连接 Azure Redis出现间歇性 java.net.UnknownHostException 异常
【Azure Redis 缓存】Redisson 连接 Azure Redis出现间歇性 java.net.UnknownHostException 异常
893 1
|
Dart 开发工具
解决升级Flutter3.0后出现警告Operand of null-aware operation ‘!‘ has type ‘WidgetsBinding‘ which excludes null
解决升级Flutter3.0后出现警告Operand of null-aware operation ‘!‘ has type ‘WidgetsBinding‘ which excludes null
338 1

热门文章

最新文章