Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
10.1.2.1
-
None
-
Debian unstable, Linux 2.6.14.2, libc 2.3.5-8, Sun JDK 1.5.0_05-b05, Derby 10.1.2.1
Description
The object names in SQLException messages are not in UTF-16, although they are sent to the server in that encoding. For example, when adding a both NULL and UNIQUE column the resulting exception message will contain the column name (like in "'é' cannot be a column of a primary key or unique key because it can contain null values.'). If the column name contained characters outside the range U+0000..U+007F these characters are not encoded in UTF-16 in the exception message. Can only reproduce with the client driver, the embedded driver behaves as expected.
Code to reproduce the issue (have a database called "sample" containing a table called "TEST"):
----%<----
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class MainDerby {
public static void main(String[] args) throws Exception {
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
try
catch (SQLException e) {
String message = e.getMessage(); // '??' cannot be a column of a primary key or unique key because it can contain null values.
System.out.println("Exception message: " + message);
System.out.print("Table name code points in exception message: ");
if (message.charAt(0) == '\'') { //
int i = 1;
char ch = message.charAt;
while (ch != '\'')
}
System.out.println();
} finally
}
}
----%<----
This program produces the following output:
----%<----
Table name code point: 233
Exception message: '??' cannot be a column of a primary key or unique key because it can contain null values.
Table name code points in exception message: 258 352
----%<----
Note "??" is the UTF-8 representation of "é".
This was initially reported as NetBeans issue 76584 (http://www.netbeans.org/issues/show_bug.cgi?id=76584).