向数据库中插入数据的时候经常会碰到null值的问题,就是数据库中的值可以是null或int等等,但java中一般数据类型不能出现null值,请问你们怎么处理这个情况。谢谢
解决方案 »
- 如何能使JButton在调用了setEnable(false) 方法后,按钮不可使用,但图像仍为正常图片,不变灰色?
- 求解 实例变量与类变量
- 把5w行记录加入到HashMap中,这样搞是不是有点离谱?
- 从远程路径上读写图片文件,出现掉色现象,如何解决?
- 求两个applet的小程序
- 求助:thinking in java 3rd里的一个问题
- getContentPane().问题
- 在DOS下编译运行Java到eclipse如何让切换
- 高分求java版的MD5算法源代码!或者Radius协议的密钥加密算法(基于MD5)
- 又来打扰各位了,新手写一个俄罗斯方块的程序,卡在这里调试不出来了,求帮助!
- 請問如何選取文件中每行的指定字符串?3Q
- 请教SWT中的Text,如何在末尾追加文字?
SQL and Java have a serious mismatch in handling null values. Specifically, using methods like getInt(), a Java ResultSet has no way of representing a SQL NULL value for any numeric SQL column. After retrieving a value from a ResultSet, it is therefore necessary to ask the ResultSet if the retrieved value represents a SQL NULL. For Java object types, a SQL NULL will often map to Java null. To avoid running into database oddities, however, it is recommended that you always check for SQL NULL.
Checking for SQL NULL involves a single call to the wasNull( ) method in your ResultSet after you retrieve a value. The wasNull() method will return true if the last value read by a call to a getXXX() method was a SQL NULL. If, for example, your database allowed NULL values for PET_COUNT column because you do not know the number of pets of all your customers, a call togetInt() could return some driver attempt at representing NULL, most likely 0. So how do you know in Java who has pets and who has an unknown number of pets? A call to wasNull() will tell you if represents an actual in the database or a NULL value in the database.