> -----Original Message-----
> From: Antony Stace [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, February 06, 2002 2:56 AM
> To: [EMAIL PROTECTED]
> Subject: Any way to pass parameters to the JDBC driver?
>
>
> Hi
>
> Is there anyway I can pass the parameters
>
> -Dfile.encoding=SJIS -Duser.language=ja
>
> to the JDBC postgres driver via the struts-config.xml file.
Actually, there are a few cautions I'll throw out.
First, file.encoding and user.language are system properties
that are JVM wide. You can set them when starting the JVM
(ie when starting your servlet engine), anything else is too
late. But frankly, I doubt you really want to do that.
Second, generally it's the responsibility of the JVM to set
them. While troubleshooting a transcoding issue a whiles
back, I did some playing around -- mostly with Solaris,
using different JVMs and different C locales (ie setting
the LANG environment variable to different things). For
SunOS 5.6 and 5.7 (aka Solaris 2.6 and 2.7) using the Sun
JDKS 1.2.2 and 1.3.1 and a range of locales, I checked the
default encoding for the JVMs and for the C locale. In
java I got the default encoding for InputStreams (based on
file.encoding) as
import java.io.InputStreamReader;
import java.io.ByteArrayInputStream;
public class Encoding {
public static void main(String[] args){
byte[] bytes = new byte[0];
ByteArrayInputStream bs = new ByteArrayInputStream(bytes);
InputStreamReader in = new InputStreamReader(bs);
System.out.println("default encoding is " + in.getEncoding());
}
}
I also got the C Codeset for the locale, which serves a similar
purpose as
#incldue <locale.h>
#include <langinfo.h>
int main(char* argv[]){
setlocale(LC_ALL, "");
printf("default encoding is %s\n", nl_langinfo(CODESET));
exit(0);
}
The some of my results were
SunOS ver LANG C JDK 1.2 JDK 1.3
-----------------------------------------------------------------------
5.6 "" "" ISO8859_1 ISO8859_1
5.6 C "" ISO8859_1 ISO8859_1
5.6 en_US ISO8859-1 ISO8859_1 ISO8859_1
5.6 en_UK ISO8859-1 ISO8859_1 ISO8859_1
5.6 hu ISO8859-2 ISO8859_2 ISO8859_2
5.6 lv ISO8859-4 ISO8859_4 ISO8859_4
5.6 ru ISO8859-5 ISO8859_5 ISO8859_5
5.7 "" 646 ISO8859_1 ASCII
5.7 C 646 ISO8859_1 ASCII
5.7 en_US ISO8859-1 ISO8859_1 ISO8859_1
5.7 en_GB ISO8859-1 ISO8859_1 ISO8859_1
5.7 hu ISO8859-2 ISO8859_2 ISO8859_2
5.7 ko 5601 EU_KR N/A
5.7 lv ISO8859-13 ASCII7 ISO8859_13
5.7 ru ISO8859-5 ISO8859_5 ISO8859_5
So, while I don't know the OS you are on, or the JVM you
are using -- I'll suggest you consider setting your locale
to something that works and let the JVM do it's thing.
In Unix this is usually done with the LANG environment
variable. On Windows, I suspect it's something in
the regional settings in the control panel.
Third, I'm wondering why care at all. I haven't played with
the Postgres driver at all, but generally this is the sort
of thing that the JDBC driver should be quite proactive about.
The system property file.encoding sets the DEFAULT transcoding
when doing IO. That gets used for stuff like reading files
on the local system, that are presumably in that encoding.
But generally a database, as a distributed system, is more
aware of transcoding issues and one would expect the JDBC
driver to use explicit transcodings. It's the JDBC driver's
responsibility to cover the difference between the Java
char type (ie UCS2) and what ever encoding the database
is storing things in. It's been a long time since I've played
with Postgres, but a quick look at the docs
http://www.us.postgresql.org/users-lounge/docs/7.1/admin/multibyte.html
makes it seem like there ought to be an easier way to get
the transcoding right. You may also want to look at the
charSet property for the Postgres jdbc driver
http://jdbc.postgresql.org/doc.html.
Don't know, but I'm betting that getting the charSet in the
jdbc driver and the encoding for the database right will
make a lot of stuff work out.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>