Subject Re: [Firebird-Java] How to set encoding of a DataSource to UTF8?
Author Rick Fincher
Hi Rio,

Items 11 and 30 in the FAQ may help. I copied them below. Item 42 may help
too. It describes all the DPB's that can be passed. That FAQ entry has an
HTML table so it would get messed up trying to send it in this e-mail,
you'll need to look it up.

If you need to pass multiple parameter in the URL, be sure to use &
instead of & (FAQ item 30). I don't know if Resin uses
java.sql.DriverManager internally, but I suspect it does. Resin may also
have a way of defining config properties like Tomcat does for data sources.
I don't know. Essentially, the server just takes those config parameters
and appends them to the URL string in the proper format.

With Tomcat one problem people sometimes run into is that the parameters in
the XML file get used to build another XML file that is used by the server
or web app. When that happens the & gets converted to & and put into
the final XML file that way. That then fails becuse when the final file is
read it needs to see an & and sees & instead.

You can get around this by manully generating the file if possible, or
possibly by tricking the parser by putting & in the first file.
That should get converted to & in the second file.

Hope this helps,

Rick

11- How do I use different character sets with JayBird?

return to top





Character Encodings:

Support for character encodings has just been added. This is easily
accessible only from the FBDriver class. To use it, request a connection
with a properties object containing a name-value pair lc_ctype=WIN1250 or
other appropriate encoding name.

URL-encoded params are fully supported only when you get a connection from
java.sql.DriverManager (using FBDriver class). For example:
jdbc:firebirdsql://localhost//home/databases/sample.gdb?lc_ctype=UNICODE_FSS

It is also possible to set lc_ctype in a deployment descriptor by adding the
following to your deployment descriptor:

<config-property>

<config-property-name>Encoding</config-property-name>

<config-property-type>java.lang.String</config-property-type>

<config-property-value>UNICODE_FSS</config-property-value>

</config-property>



--------------------------



30- Why don't arguments or ampersands (&) work in my URL?

return to top



If you are using an XML file to pass the parameters (Tomcat, etc.) you must
use & or & instead of the ampersand (&) alone.

In XML, the & symbol is used to make references to entities, so it is
treated like a special character. The XML parser expects to find something
like &entityname; That is why it must end with the ';' delimiter.

If you see an error message like:

org.apache.commons.digester.Digester fatalError
SEVERE: Parse Fatal Error at line 62 column 94: The reference to entity
"lc_ctype" must end with the ';' delimiter.
org.xml.sax.SAXParseException: The reference to entity "lc_ctype" must end
with the ';' delimiter.

This is what is causing it.

Instead of: ...my.gdb?sql_role_name=guest&lc_ctype=WIN1251


Use: ...my.gdb?sql_role_name=guest&lc_ctype=WIN1251



------------------------------------------------------






----- Original Message -----

> Hi,
>
> I'm trying to get my UTF8-encoded data out from database using
> DataSource via JNDI look-up but the output seems to be garbled. I
> suspected that this is because there is no encoding information
> stored somewhere along the process. What confuses me is that there
> is no way to set this property to the resulting DataSource.
>
> I used Resin 2.1.6 and firebirdsql 1.0.1 JDBC driver. The following
> is my DataSource configuration excerpted from resin.conf, Any
> comments would be appreciated.
>
> =================
> <resource-ref>
> <res-ref-name>jdbc/test</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <init-param driver-name="org.firebirdsql.jdbc.FBDriver"/>
> <init-param
> url="jdbc:firebirdsql:127.0.0.1/3050:/opt/db/test.GDB"/>
> <init-param user=""/>
> <init-param password=""/>
> <init-param max-connections="20"/>
> <init-param max-idle-time="30"/>
> <init-param enable-cache="true"/>
> <init-param cache-size="5"/>
> <init-param connection-time-out="15"/>
> </resource-ref>
> ==================
>
>
> Thanks,
>
> Rio