Set - 4

Question 21 :

How can I avoid ResourceExceptions when sending more requests for database connections from the pool than are currently available?

Answer :

The fundamental problem is too few resources (database connections in the connection pool) for the work load. The correct response is to increase the maximum number of connections in the connection pool. Optimally designed applications only require the server to have one pool connection per execute thread.
The proper application response to a resource exception is not to retry the request in a tight loop, which would tie up execute threads on the server.
You should design your application to gracefully fail if no connections are available. Try to ensure that you get the connection as late as possible in your application code and return them to the pool as early as possible so that you do not see as many NoResource exceptions. It is better to have the connection as a method level variable and close the connection in a finally block as in the following example:

} catch(Exception handleEx) {
} finally {
try{ conn.close();
}catch (Exception ignore){} // always return the connection to pool

Question 22 :

How do I use Unicode codesets with the WebLogic jDriver for Oracle driver?

Answer :

To use Unicode codesets:
1. Install the appropriate codeset when you install Oracle. If you did not do this in the original installation, you will need to re-run the Oracle installer and install the proper codeset.
2. Define the NLS_LANG variable in the environment where the JDBC driver is running. Do this by assigning the proper codeset to NLS_LANG in the shell from where you start the WebLogic Server.
The Developers Guide has more information about internationalization support.

Question 23 :

How do I bind string values in a PreparedStatement?

Answer :

Suppose you are trying to tget the PreparedStatement class to bind Strings in a statement. The setString() method doesn't seem to work. Here is how you have set up the PreparedStatement:

String pstmt = "select n_name from n_table where n_name LIKE
PreparedStatement ps = conn.prepareStatement(pstmt);
ps.setString(1, "SMIT");
ResultSet rs = ps.executeQuery();

The preceding code does not work because the complete value needs to be specified in a String (without using embedded quotes) and then bound to an unquoted question-mark (?). Here is the corrected code:

String matchvalue = "smit%";
String pstmt = "select n_name from n_table where n_name LIKE ?";
PreparedStatement ps = conn.prepareStatement(pstmt);

ps.setString(1, matchvalue);
ResultSet rs = ps.executeQuery();

Question 24 :

How do I look up an "ORA" SQLException?

Answer :

If your WebLogic jDriver for Oracle application produces an SQLException such as:
java.sql.SQLException: ORA-12536: TNS: operation would block
You can look up an Oracle error by using the oerr command. For example, the description of error ORA-12536 can be found with the command:
> oerr ora 12536

Question 25 :

What is error "ORA-6502?"

Answer :

The default length of a string bound to an OUTPUT parameter of a CallableStatement is 128 characters. If the value you assign to the bound parameter exceeds that length, you will get this error.
You can adjust the length of the value of the bound parameter by passing an explicit length with the scale argument to the CallableStatement.registerOutputParameter() method.