The ORA-12705 error typically occurs when Oracle cannot find or access National Language Support (NLS) data files during database operations. In JDBC connections, this often manifests when:
- The Oracle client environment isn't properly configured
- NLS_LANG parameter mismatches exist between client and server
- File permissions prevent access to NLS data
- ORACLE_HOME path is incorrectly set
Before diving into solutions, verify these critical points:
// Check your current NLS settings in SQL*Plus
SELECT * FROM nls_session_parameters;
SELECT * FROM v$nls_parameters;
Compare these with your Java environment's NLS settings using:
System.getProperties().list(System.out);
Solution 1: Explicit NLS_LANG Specification
Modify your connection code to explicitly set NLS parameters:
import java.sql.*;
import java.util.Properties;
public class OracleConnect {
public static void main(String[] args) {
String url = "jdbc:oracle:thin:@hostname:1521:oracle";
Properties props = new Properties();
props.put("user", "username");
props.put("password", "password");
props.put("oracle.jdbc.defaultNChar", "false");
props.put("oracle.net.ns_lang", "AMERICAN_AMERICA.AL32UTF8");
try (Connection con = DriverManager.getConnection(url, props)) {
System.out.println("Connection successful!");
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
Solution 2: Environment Variable Verification
Ensure these environment variables are properly set before Java execution:
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_HOME=/path/to/oracle/client
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
Case: Missing NLS Data Files
If the error persists, verify NLS data file presence in:
$ORACLE_HOME/nls/data
Common required files include:
- lx00001.nlb
- lx10001.nlb
- lx20001.nlb
Case: Multiple Oracle Homes Conflict
When multiple Oracle installations exist, force the correct home:
// In Java code before connection
System.setProperty("oracle.net.tns_admin", "/correct/path/to/network/admin");
System.setProperty("oracle.home", "/correct/oracle/home");
For ojdbc6.jar or later drivers, try these connection properties:
props.put("oracle.jdbc.useNio", "false");
props.put("oracle.jdbc.convertNioHeapBuffers", "false");
For connection pools (like HikariCP), configure as follows:
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:oracle:thin:@hostname:1521:oracle");
config.addDataSourceProperty("oracle.jdbc.defaultNChar", "false");
config.addDataSourceProperty("oracle.net.ns_lang", "AMERICAN_AMERICA.AL32UTF8");
// Other pool configurations...
Check database server NLS configuration:
-- As DBA
SELECT * FROM v$nls_valid_values WHERE parameter = 'LANGUAGE';
SELECT * FROM v$nls_valid_values WHERE parameter = 'TERRITORY';
SELECT * FROM v$nls_valid_values WHERE parameter = 'CHARACTERSET';
Ensure server and client NLS settings are compatible. Common recommended pairings:
Server Setting | Recommended Client Setting |
---|---|
AMERICAN_AMERICA.AL32UTF8 | AMERICAN_AMERICA.AL32UTF8 or AMERICAN_AMERICA.UTF8 |
AMERICAN_AMERICA.WE8ISO8859P1 | AMERICAN_AMERICA.WE8ISO8859P1 |
You're working with Oracle 10gR2 on RHEL 4.0, successfully connecting via SQL*Plus and iSQL*Plus, but when your Java application tries to establish a JDBC connection, it throws:
java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-12705: Cannot access NLS data files or invalid environment specified
The ORA-12705 error typically occurs when Oracle cannot find or properly access its National Language Support (NLS) data files. This is particularly common in Java applications because:
- The Oracle client environment isn't properly initialized in the JVM context
- NLS-related environment variables aren't properly set
- There's a mismatch between the Oracle client version and database version
Solution 1: Explicitly Set NLS Environment Variables
Before establishing the connection, set these properties in your Java code:
System.setProperty("oracle.jdbc.defaultNChar", "true");
System.setProperty("oracle.net.ns_charset", "UTF8");
System.setProperty("user.language", "en");
System.setProperty("user.region", "US");
Solution 2: Verify Oracle Client Configuration
Ensure your Oracle client installation has these critical files:
- $ORACLE_HOME/nls/data/*.nlb
- $ORACLE_HOME/nls/mesg/*.msb
If files are missing, reinstall the Oracle client or copy them from another working installation.
Solution 3: Use OCI Driver Instead of Thin Driver
Modify your connection URL:
String url = "jdbc:oracle:oci:@hostname:1521:oracle";
Note: This requires Oracle client libraries to be installed on the host.
Here's a robust connection example with error handling:
import java.sql.*;
public class OracleConnector {
public static void main(String[] args) {
// Set NLS environment before any Oracle calls
System.setProperty("oracle.jdbc.defaultNChar", "true");
String url = "jdbc:oracle:thin:@hostname:1521:oracle";
String user = "username";
String pass = "password";
try {
// Explicitly load driver (not always needed in newer JDBC)
Class.forName("oracle.jdbc.driver.OracleDriver");
// Set connection properties
java.util.Properties props = new java.util.Properties();
props.setProperty("user", user);
props.setProperty("password", pass);
props.setProperty("defaultNChar", "true");
Connection conn = DriverManager.getConnection(url, props);
// Verify connection
try (Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM v$version")) {
while (rs.next()) {
System.out.println(rs.getString(1));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
If the issue persists:
- Check $ORACLE_HOME environment variable points to correct location
- Verify LD_LIBRARY_PATH includes $ORACLE_HOME/lib
- Ensure the Oracle user has read permissions on NLS files
- Try setting NLS_LANG environment variable explicitly:
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
Remember that Oracle 10gR2 is quite old, and upgrading to a supported version might resolve many compatibility issues.