2

I am new to JDBC, and I found something strange when I use:

catch (SQLException e) {
    System.out.println("Error STATE: " + e.getSQLState());
    System.out.println("With the following message: " + e.getMessage() );
}

Sometimes the message is parsed, but sometimes not.

Like:

First:
enter image description here

Second:
enter image description here

One is parsed, while the other is not, but I can get the error message through googling the corresponding error code.

I don't know what's going on.. And I have tried googling it but with no similar question posted. Does it mean my java.sql.* library is incomplete?

All help would be appreciated.

7
  • Please post the error text inline, and as simple text, not as an image. Commented Nov 8, 2015 at 15:09
  • 1
    This seems like some of your exceptions may have their messages coming from a different localization. Commented Nov 8, 2015 at 15:19
  • i'd suggest to debug it and see exactly what is stored in the exception variable at the time Commented Nov 8, 2015 at 15:20
  • 1
    Also note that your first message is not the output of the code you have shown. In your code, STATE is in capitals, and the message is prefixed with With the following message - and these do not appear in your first output. Commented Nov 8, 2015 at 15:27
  • Right, they are basically same.. I just adjust what is in front in different scenerios... Commented Nov 8, 2015 at 15:32

1 Answer 1

3

It means your operating system settings don't support the symbols for the error message in the language being used. The ORA-01017 message is coming before the database applies your language setting so in in English, and more importantly in Western script. Once you've connected the Java locale is honoured.

For example, I can see both these from the same code run with java -Duser.language=zh -Duser.country=CN; the first has incorrect credentials supplied, the second is trying to create an existing table:

java.sql.SQLException: ORA-01017: invalid username/password; logon denied

java.sql.SQLSyntaxErrorException: ORA-00955: 名称已由现有对象使用

I'm seeing ten symbols, where you are seeing ten question marks. My operating system session (Linux in this case) has LANG=en_US.UTF-8. If I change that to something which has fewer symbols defined, e.g. export LANG="en_US.ASCII", I still see the first message but now I get the same as you for the second one:

java.sql.SQLException: ORA-01017: invalid username/password; logon denied

java.sql.SQLSyntaxErrorException: ORA-00955: ??????????

The Chinese symbols can now no longer be rendered by my operating system session.

So set your operating system locale to something that can represent the symbols of the language you're using, preferably UTF8. For example, if Java is running with a Chinese locale, you could do this to be consistent under Linux:

export LANG="zh_CN.UTF-8"
java -Duser.language=zh -Duser.country=CN

ORA-00955: 名称已由现有对象使用

Or change your Java locale to English-language if you want to see all the messages in English:

export LANG="en_CN.UTF-8"
java -Duser.language=en -Duser.country=CN -

ORA-00955: name is already used by an existing object

(Although Java should pick up the language from your locale by default anyway, so maybe don't supply the language or country explicitly in the java call at all; just setting LANG properly would then be enough)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.