* & Nbsp; * Test. java2008-7-30 & nbsp; * importjava. SQL. connection; importjava. SQL. driverManager; importjava. SQL. resultSet; importoracle. jdbc. oracleDriver; publicclassTest {&
/*
* Test. java 2008-7-30
*
*/
Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. ResultSet;
Import oracle. jdbc. OracleDriver;
Public class Test {
Public static void main (String [] args) throws Exception {
DriverManager. registerDriver (new OracleDriver ());
// Normal
Connection conn = getConnection ();
ResultSet rs = conn.createstatement(cmd.exe cuteQuery (
App2db ("SELECT '123abc who am I? 'From dual "));
Rs. next ();
// Print 123abc. Who am I?
System. out. println (db2app (rs. getString (1 )));
// Exception
// Because the print ORA-00921: unexpected end of SQL command
// Result print ORA-00921 :???? SQL ????
Try {
Conn.createstatement(cmd.exe cuteQuery ("SELECT 1 from dual where ");
} Catch (Exception e ){
System. out. println (e. getMessage ());
}
// Because of this print ORA-00920: invalid relational operator
// Result print ORA-00920 :????????
Try {
Conn.createstatement(cmd.exe cuteQuery ("SELECT 1 from dual where 1 ");
} Catch (Exception e ){
System. out. println (e. getMessage ());
}
// Because the print ORA-00904: "X": invalid identifier
// Print the result ORA-00904: "X ":??????
Try {
Conn.createstatement(cmd.exe cuteQuery ("SELECT x FROM x ");
} Catch (Exception e ){
System. out. println (e. getMessage ());
}
}
Private static String app2db (String str) throws Exception {
Return new String (str. getBytes (), "ISO-8859-1 ");
}
Private static String db2app (String str) throws Exception {
Return new String (str. getBytes ("ISO-8859-1 "));
}
Private static Connection getConnection () throws Exception {
Return DriverManager. getConnection ("jdbc: oracle: thin :......");
}
}
Solution:
You can consider setting the NLS_LANG environment variable of the machine where the Oracle client is located (also the machine where your application runs) to bypass this problem.
I did a test on my machine. The results are as follows:
System Environment
Windows 2003 Simplified Chinese version, Oracle 10g
Procedure
1.execute cmd.exe to open a command line window
2. Run sqlplus username/password to enter the SQL Plus command prompt.
3. Execute the following SQL statement
SQL code
Select 'x' from dua;
Select 'x' from dua;
Note that dua was intentionally written incorrectly (dual missing the l) to get an oracle exception.
The error message is as follows:
Reference
Row 3 has an error:
ORA-00942: Table or view does not exist
4. Run quit to exit the SQL Plus command prompt.
5. Run the following command at the command line prompt of the operating system:
Java code
Set nls_lang = AMERICAN_AMERICA.WE8ISO8859P1
Set nls_lang = AMERICAN_AMERICA.WE8ISO8859P1
6. Repeat steps 2nd and 3
The error message is as follows:
Reference
ERROR at line 1:
ORA-00942: table or view does not exist
We can see that the original error message is in Chinese and the error message is in English. This is exactly what you need