Hi Ben,
Good news, this can be fixed and has to be fixed on our side. In
sqlserver you have to prepend your string with N for unicode, for
example:
INSERT INTO DEPARTMENTS( NAME, BUSINESS_UNIT, UPDATE_TIMESTAMP) VALUES
( N'junit', N'中文', '2011-11-09 20:28:40.718')
Change DBDatabaseDriver line 664 to the following to fix the issue:
valBuf.append("N'");
Rainer, how would we fix this? getValueString() in DBDatabaseDriver is
final. We could do this by default or have an option to enable the
N's.
Cheers,
Francis
On Wed, Nov 9, 2011 at 4:57 AM, Ben Ng <[email protected]> wrote:
> Hi Francis,
>
> Attached with a project which can reproduce my issue. Thanks
>
> Cheers,
> Ben
>
> On Wed, Nov 9, 2011 at 5:07 AM, Francis De Brabandere <[email protected]>
> wrote:
>>
>> Hi Ben,
>>
>> Any chance you could set up a very small project to reproduce this
>> encoding issue?
>> Something like this:
>>
>> https://svn.apache.org/repos/asf/incubator/empire-db/tags/apache-empire-db-2.2.0-incubating/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java
>>
>> Cheers,
>> Francis
>>
>>
>>
>> On Tue, Nov 8, 2011 at 2:50 AM, Ben Ng <[email protected]> wrote:
>> > Dear Francis,
>> >
>> > I am now using MS SQL Server 2008. I have tried two JDBC drivers. Both
>> > are
>> > fail to store Chinese character without prepared statements.
>> > 1) net.sourceforge.jtds.jdbc.Driver (jtds-1.2.jar)
>> > 2) com.microsoft.sqlserver.jdbc.SQLServerDriver (sqljdbc4.jar latest
>> > version)
>> >
>> > Collation of the database is SQL_Latin1_General_CP1_CI_AS and the field
>> > is a
>> > NVARCHAR.
>> > Hope that those information can be helpful to you. Thanks
>> >
>> > Best wishes,
>> > Ben
>> >
>> >
>> > On Mon, Nov 7, 2011 at 10:34 PM, Francis De Brabandere
>> > <[email protected]>
>> > wrote:
>> >>
>> >> Ben, could you tell us what database and driver version you are using?
>> >>
>> >> I'll try to create a unit/integration test for this.
>> >>
>> >> Cheers,
>> >> F
>> >>
>> >> On Mon, Nov 7, 2011 at 3:25 PM, Rainer Döbele <[email protected]>
>> >> wrote:
>> >> > Hi Francis,
>> >> >
>> >> > I agree but we need a test case for this.
>> >> > It may as well depend on the JDBC-Driver used - in fact I don't know.
>> >> > Also my Chinese is a little rusted ;-)
>> >> >
>> >> > Regards
>> >> > Rainer
>> >> >
>> >> >> from: Francis De Brabandere [mailto:[email protected]]
>> >> >> to: [email protected]
>> >> >> re: Re: Inserting Chinese character record to DB
>> >> >>
>> >> >> I think this still is something we should fix for non-prepared
>> >> >> statements
>> >> >>
>> >> >> On Mon, Nov 7, 2011 at 9:41 AM, Ben Ng <[email protected]> wrote:
>> >> >> > Hi Rainer,
>> >> >> >
>> >> >> > It seems that my problem have been solved when I enable prepared
>> >> >> statement.
>> >> >> > Thank you for your help.
>> >> >> >
>> >> >> > Regards,
>> >> >> > Ben
>> >> >> >
>> >> >> > On Mon, Nov 7, 2011 at 4:19 PM, Rainer Döbele <[email protected]>
>> >> >> wrote:
>> >> >> >>
>> >> >> >> Hi Ben,
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> I don't know for sure but it may be a good idea to tell Empire-db
>> >> >> >> to
>> >> >> >> use prepared statements.
>> >> >> >>
>> >> >> >> Simply write:
>> >> >> >>
>> >> >> >> db.setPreparedStatementsEnabled(true);
>> >> >> >>
>> >> >> >> in your initialization code.
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> Please let us know whether this works and tell us which DBMS and
>> >> >> >> JDBC-Driver you are using.
>> >> >> >>
>> >> >> >> Regards
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> Rainer
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> from: Ben Ng [mailto:[email protected]]
>> >> >> >> to: [email protected]
>> >> >> >> re: Re: Inserting Chinese character record to DB
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> Hi Empire-DB team,
>> >> >> >>
>> >> >> >> I am trying to insert a record with Chinese character from my JSP
>> >> >> >> page.
>> >> >> >> The encoding is set to UTF-8 already and I am trying to insert
>> >> >> >> the
>> >> >> >> record by the code below where "remarks" is a string contain
>> >> >> >> Chinese
>> >> >> characters.
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> DBRecord rec = new DBRecord();
>> >> >> >> rec.create(db.REQUESTS);
>> >> >> >> rec.setValue(db.REQUESTS.REMARKS, remarks); rec.update(conn);
>> >> >> >>
>> >> >> >> After inserting the record, the data of the field REMARKS become
>> >> >> >> "???".
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> I tried to use traditional method(PreparedStatement) to insert
>> >> >> >> this
>> >> >> >> record by using the same db and connection.
>> >> >> >> The data can be inserted correctly.
>> >> >> >> Is there any step I have missed in my code so it can support
>> >> >> >> UTF-8?
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> I really appreciate for what your team have done. Thanks a lot.
>> >> >> >>
>> >> >> >> Thanks & Regards,
>> >> >> >> Ben
>> >> >> >
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> http://www.somatik.be
>> >> >> Microsoft gives you windows, Linux gives you the whole house.
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> http://www.somatik.be
>> >> Microsoft gives you windows, Linux gives you the whole house.
>> >
>> >
>>
>>
>>
>> --
>> http://www.somatik.be
>> Microsoft gives you windows, Linux gives you the whole house.
>
>
--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.