Jump to content
We've recently updated our Privacy Statement, available here ×

Encoding problem (getting data from database)


2004 IR Help

Recommended Posts

By: Kostya - bce77

Encoding problem (getting data from database)

2005-04-21 10:13

Database is using windows-1251 (Cyrillic) encoding. In windows I exports in pdf and xls without any problems.

But when I run exactly the same code under fedora core 3 (UTF-8) I see dots and white spaces.

Looks like someone (Jasper? or Java) transliterate data from database and parameters according to system default encoding.

So how can I change it?

p.s.

Static text looks fine in Russian in windows and Linux.

 

 

 

 

 

By: CleverFool - cleverfool

RE: Encoding problem (getting data from datab

2005-04-24 04:10

Думаю, что это делает Java. Какая база?

 

 

 

 

By: CleverFool - cleverfool

RE: Encoding problem (getting data from datab

2005-04-24 04:10

ijì¾, ??ë¥òŠ¡va. Êê¿ á§à¿Š

 

 

 

 

By: raghav - raghav_2004

RE: Encoding problem (getting data from database)

2005-04-24 22:44

Hay use this method:

 

static String NCR2UnicodeString(String str)

{

String ostr = new String();

int i1=0;

int i2=0;

 

while(i2<str.length())

{

i1 = str.indexOf("",i2);

if (i1 == -1 ) {

ostr += str.substring(i2, str.length());

break ;

}

ostr += str.substring(i2, i1);

i2 = str.indexOf(";", i1);

if (i2 == -1 ) {

ostr += str.substring(i1, str.length());

break ;

}

 

String tok = str.substring(i1+2, i2);

try {

int radix = 10 ;

if (tok.trim().charAt(0) == 'x') {

radix = 16 ;

tok = tok.substring(1,tok.length());

}

ostr += (char) Integer.parseInt(tok, radix);

} catch (NumberFormatException exp) {

ostr += '?' ;

}

i2++ ;

}

return ostr ;

}

 

Hope it works!

 

 

 

 

By: Kostya - bce77

RE: Encoding problem (getting data from datab

2005-04-25 03:14

Solution for database:

Set connection property "charSet" with appropriate value (for example: "Cp1251"). With jaybird driver the property is "lc_ctype" and value - "WIN1251"!

Actually I used something like this:

Properties p = new Properties();

p.put("user", user);

p.put("password", password);

p.put("lc_ctype", "WIN1251");

Class.forName(driver);

Connection conn = DriverManager.getConnection(connectString, p);

 

Solution for parameters from file (Cp1251):

BufferedReader file = new BufferedReader(new InputStreamReader(new FileInputStream(paramFileName), "Cp1251"));

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...