- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to handle Null values while working with JDBC?
SQL's use of NULL values and Java's use of null are different concepts. So, to handle SQL NULL values in Java, there are three tactics you can use:
Avoid using getXXX( ) methods that return primitive data types.
Use wrapper classes for primitive data types, and use the ResultSet object's wasNull( ) method to test whether the wrapper class variable that received the value returned by the getXXX( ) method should be set to null.
Use primitive data types and the ResultSet object's wasNull( ) method to test whether the primitive variable that received the value returned by the getXXX( ) method should be set to an acceptable value that you've chosen to represent a NULL.
Example
Following code snippet demonstrates how to handle null values in Java.
Statement stmt = conn.createStatement( ); String sql = "SELECT id, first, last, age FROM Employees"; ResultSet rs = stmt.executeQuery(sql); int id = rs.getInt(1); if( rs.wasNull( ) ) { id = 0; }
- Related Articles
- How to handle Exceptions while working with JDBC applications?
- How to handle errors while working with Navigation in ReactNative?
- How to handle the null values while comparing the two series objects using series.eq() method?
- Is it mandatory to register the driver while working with JDBC?
- How to concat Values in MySQL Query and to handle Null values as well?
- How to handle date in JDBC?
- How does the pandas series.equals() method handle the null values?
- How to remove null values with PHP?
- Working with NULL and IS NOT NULL in MySQL
- How to handle indexes in JavaDB using JDBC program?
- How to set/insert null values to in to a column of a row using JDBC program?
- How to create a table with decimal values using JDBC?
- How does COALESCE order results with NULL and NON-NULL values?
- How can we handle NULL values stored in a MySQL table by using PHP script?
- Ignore NULL and UNDEFINED values while running a MongoDB query

Advertisements