|
public class NCHARsupport4UnicodeSample
{
.......................
/**
* Updates the Product Name and Description of the
product to the
* Product_Descriptions table. Here the Product Name
and Description columns
* are of type NVARCHAR2.
**/
public void updateProductDetails() {
.......................
// PreparedStatement object
to update the product details
PreparedStatement pstmt = null;
.......................
try {
.......................
// The only difference in usage between the SQL CHAR
and SQL NCHAR
// datatypes occur in a data bind situation. The JDBC
program must call the
// setFormOfUse() method to specify if the data is
bound for a SQL NCHAR
// datatype and it must be called before binding Java
variables to
// SQL NCHAR datatypes.
((OraclePreparedStatement)pstmt).setFormOfUse(1,OraclePreparedStatement.FORM_NCHAR);
// Set the Product Name
pstmt.setString(1,productName);
((OraclePreparedStatement)pstmt).setFormOfUse(2,OraclePreparedStatement.FORM_NCHAR);
// Set the Product Description
pstmt.setString(2,productDesc);
.......................
// Execute the update
pstmt.executeUpdate();
} catch(Exception ex) { // Trap
errors
.......................
}
}
/**
* Inserts the translated Product name and Product
Description into
* Product_Descriptions table.
**/
public void insertProductDetails() {
.......................
// PreparedStatement object
to update the product details
PreparedStatement pstmt = null;
.......................
try {
.......................
// The only difference in usage between the SQL CHAR
and SQL NCHAR
// datatypes occur in a data bind situation. The JDBC
program must call the
// setFormOfUse() method to specify if the data is
bound for a SQL NCHAR
// datatype and it must be called before binding Java
variables to
// SQL NCHAR datatypes.
((OraclePreparedStatement) pstmt).setFormOfUse(3,
OraclePreparedStatement.FORM_NCHAR);
// Set the Product Name
pstmt.setString(3, productName);
((OraclePreparedStatement)
pstmt).setFormOfUse(4,
OraclePreparedStatement.FORM_NCHAR);
// Set the Product Description
pstmt.setString(4, productDesc);
// Execute the insert
int inserted = pstmt.executeUpdate();
} catch(Exception ex) { // Trap
errors
.......................
}
}
.......................
|