Attaching derby-2066-01-aa-makeMessageIDaSQLState.diff. This results in a reasonable error message for this situation. I will run regression tests.
I don't propose to commit this patch before creating the 10.8 branch. I would like to give people time to consider whether there are any problems with this solution:
The worthless error message arises because the error condition creates a SQLException with no SQLState. In various places the network driver assumes that all SQLExceptions have SQLStates. In one place the network driver assumes that a SQLState will have exactly 5 characters. If these assumptions aren't true, then the protocol trips over NPEs and array bounds exceptions and coughs up the worthless error message seen in this bug report.
Although I can fault the driver's graceless handling of violated assumptions, I think that it is reasonable to insist that all SQLExceptions have 5 character SQLStates.
The "unregistered driver" error is raised twice in Derby code. In both cases it surfaces as a SQLException without a SQLState. The actual message handle for this error lives in MessageId.java. Comments in that class indicate that it is only for messages which DON'T appear in SQLExceptions.
I fixed the problem as follows:
1) Moved the "unregistered driver" message from MessageId into SQLState. Along the way I gave it a new message handle and placed it in a block with other connection errors.
2) Adjusted messages.xml accordingly.
3) Changed the two places which raise this SQLException to also include the SQLState.
If this seems like a reasonable way to ungarble this problem, then I think it would be worthwhile to examine MessageId to see if it contains other errors which are really surfacing as SQLExceptions. Those errors should get valid SQLStates and should move to SQLState.java too.
Touches the following files:
Make the "unregistered driver" error a SQLState rather than a MessageId.
Include a SQLState in the "unregistered driver" SQLException.