2
votes

We have a code for creating folders from within database (java / PL/SQL combination).

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "rtp_java_utils" AS  
import java.io.*;  

public class rtp_java_utils extends Object  
{  
  public static int mkdir (String path) {  
    File myFile = new File (path);  
    if (myFile.mkdir()) return 1; else return 0;  
  }  
}  

CREATE OR REPLACE FUNCTION mkdir (p_path  IN  VARCHAR2) RETURN NUMBER  
AS LANGUAGE JAVA   
NAME 'rtp_java_utils.mkdir (java.lang.String) return java.lang.int'; 

Recently we started using Oracle 12c database and now we are having problems with folders containing special characters in their names (for example "š", "č" ot "đ"). Folders are created but without special characters - instead some character combinations are shown. For example, with parameter "d:/test/testing š č đ" created folder is "test š ÄŤ Ä‘". So, 2 characters are used for every special character.

Database is version 12C (12.1.0.2.0) with NLS_CHARACTERSET AL32UTF8. File system is NTFS with UTF-8 encoding. OS is Windows server 2012. Some Java system properties are: - file.encoding UTF-8 - sun.io.unicode.encoding UnicodeLittle

Interesting is, we get the same result (the same false folder name) regardless if NTFS file system encoding is UTF-8 or WINDOWS-1250. We tried both options.

Our guess is, that java is doing some implicit conversions of given folder name from one character set to another, and final result is false folder name. But everything we tried (explicit folder name conversions in PLSQL or java, system parameters change in java...) hasn't worked.

On our previous database everything was working great (database version 10.1.0.5.0 with EE8MSWIN1250 characterset, NTFS file system with windows-1250 encoding).

Does anyone have an idea, what is wrong?

Thank You!

1

1 Answers

1
votes

Somewhere in your (not posted) code the bytes of the UTF8 string are used to construct a string with ISO8859 encoding.

See following snippet

String s = "test š č đ";
System.out.println("UTF8   : " 
        + Arrays.toString(s.getBytes(StandardCharsets.UTF_8)));
System.out.println("ISO8895: " 
        + Arrays.toString(s.getBytes(StandardCharsets.ISO_8859_1)));
Files.createDirectories(Paths.get("c:/temp/" + s));
byte[] utf8Bytes = s.getBytes(StandardCharsets.UTF_8);
Files.createDirectories(Paths.get("c:/temp/" 
        + new String(utf8Bytes, StandardCharsets.ISO_8859_1)));
}

outout

UTF8   : [116, 101, 115, 116, 32, -59, -95, 32, -60, -115, 32, -60, -111]
ISO8895: [116, 101, 115, 116, 32, 63, 32, 63, 32, 63]

and it this will create in c:/temp the directories

test š č đ
test Å¡ Ä Ä

Try to print the bytes of the sctring you pass to your stored function.