Over 10 Million Study Resources Now at Your Fingertips


Download as :
Rating : ⭐⭐⭐⭐⭐
Price : $10.99
Language:EN
Pages: 2

And the price column defined database number

Chapter 15: Running SQL Using Java 549

Handling Numbers
This section describes the issues associated with storing numbers in your Java programs. An Oracle database is capable of storing numbers with a precision of up to 38 digits. In the context of number representation, precision refers to the accuracy with which a floating-point number may be represented in a digital computer’s memory. The 38 digits level of precision offered by the database allows you to store very large numbers.

In addition to these types, there is one of the Oracle JDBC extension types you can use to store your integers or floating-point numbers. This type is oracle.sql.NUMBER, and it allows you to store numbers with up to 38 digits of precision. You’ll learn more about the oracle.sql .NUMBER type later in this chapter. In Oracle Database 10g and above, you can use the oracle .sql.BINARY_FLOAT and oracle.sql.BINARY_DOUBLE types. These types allow you to store the BINARY_FLOAT and BINARY_DOUBLE numbers.

Let’s take a look at some examples of using these integer and floating-point types to store the product_id and price column values for a row retrieved from the products table. Assume that a ResultSet object named productResultSet has been populated with the product_ id and price columns for a row from the products table. The product_id column is defined

Bits
16

–32768

32767

32
64

–9223372036854775808

9223372036854775807

Bits Low Value High Value

float

32 –3.4E+38 3.4E+38

6 digits

64 –1.7E+308 1.7E+308

short productIdShort = productResultSet.getShort("product_id");

int productIdInt = productResultSet.getInt("product_id");

Notice the use of the different get methods to retrieve the column values as the different types, the output of which is then stored in a Java variable of the appropriate type.

Handling Database Null Values
A column in a database table may be defined as being NULL or NOT NULL. NULL indicates that the column may store a NULL value; NOT NULL indicates that the column may not contain a NULL value. A NULL value means that the value is unknown. When a table is created in the database and you don’t specify that a column is NULL or NOT NULL, the database assumes you mean NULL.

There are two ways to get around this problem:

You can use the wasNull() method in the ResultSet. The wasNull() method returns true if the value retrieved from the database was NULL; otherwise, the method returns false.

How It Works
Login account
Login Your Account
Add to cart
Add to Cart
Payment
Make payment
Document download
Download File
PageId: ELI8746C60
img
Uploaded by :
AbA9ywRE
Page 1 Preview
and the price column defined database number
Sell Your Old Documents & Earn Wallet Balance