Processing of NULL in Oracle Database

Source: Internet
Author: User

The concept of null in java: in java, null indicates that a class or variable is null and does not represent any object or instance. You can assign null to a reference type variable, however, null cannot be assigned to basic type variables. The concept of NULL in a database: null in a database indicates that null is not filled, unknown, or unavailable. Unlike java, NULL can be assigned to any data type in a database. In this way, after reading the field value from the database, how can we determine whether the read value is null in the java program? Is x = null used? Obviously not, unless X is of the String type. The wasNull () method in ResultSet can solve this problem:
WasNull (): report whether the last read column has a value of SQL NULL. Note: you must first call a get method for the column to try to read its value, and then call the wasNull method to check whether the read value is SQL NULL.
 
String value = "";
Int n;
While (rs. next ()){
Value = rs. getString ("name ");
If (rs. wasNull ()){
System. out. println ("null ");
} Else {
System. out. println (value );
}

N = rs. getInt ("number ");
If (rs. wasNull ()){
System. out. println ("null ");
} Else {
System. out. println (n );
}
}
 
Author: ERDP Technical Architecture"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.