One more question if I can - Is there some way or reason to implement own appender and process Log4J messages in my way? After all, there is no problem with inserting unicode strings into a PostgreSQL database via PostgreSQL JDBC 4 driver (or com.jolbox.bonecp.BoneCPDataSource datasource in my case). If is it possible to have a custom implementation of inserting messages into database, the problem will be solved. I'll check it.
M. 2013/7/16 Nick Williams <[email protected]>: > Actually I need to correct myself: > > On Jul 16, 2013, at 7:57 AM, Nick Williams wrote: > >> M., >> >> setNString() is part of JDBC 4.0, which came with Java 6. It sounds like you >> are using the postgresql-x.x-xxxx.jdbc3.jar JDBC driver, which was written >> for Java 4. Please download the latest JDBC driver >> postgresql-9.2-1003.jdbc4.jar >> (http://jdbc.postgresql.org/download/postgresql-9.2-1003.jdbc4.jar). >> However, you should note that PostgreSQL's website says the following: >> >>> Support for JDBC4 methods is not complete, but the majority of methods are >>> implemented. >> >> So it's possible that even the latest driver is not fully JDBC 4.0 compliant >> and won't support this method. In that case, there's nothing we can do about >> it. > > There is something you can do about it: don't use unicode columns. Look at > the documentation for the JDBC Appender > (http://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender) and > scroll down to the "Column Parameters" table. Each String <Column> you define > defaults to unicode (because unicode is the best way for storing Java unicode > Strings). If you use the defaults (all String columns are unicode) then the > database columns for your table must be NVARCHAR (not VARCHAR) and Log4j will > use setNString. However, if you add isUnicode="false" to the String columns, > Log4j will use setString (and your database columns must be VARCHAR, not > NVARCHAR). > > To be clear, it's really best and most efficient to store these values > unicode. However, if the latest PostgreSQL driver still does not support > setNString (again, this is a "bad thing"), you can use isUnicode="false" to > get around this. > >> PostgreSQL has had 7 years to implement a JDBC 4.0 driver; you'll need to >> complain to them. JDBC 4.1 came out two years ago and JDBC 4.2 comes out >> next March. I suppose it'll be ~2020 before they implement those. :-/ >> >> Opinion Section: Based on my reading of PostgreSQL website, it doesn't sound >> like a very Java-friendly database to use if you want to use modern versions >> of Java. At least MySQL and Microsoft SQL Server support JDBC 4.0 (which >> Log4j requires) though they still haven't implemented JDBC 4.1 (which Log4j >> does not require). Only Oracle fully supports JDBC 4.1 right now (sad face). >> >> Nick >> >> On Jul 16, 2013, at 6:18 AM, Betty User wrote: >> >>> Hello, >>> >>> I am trying to log Log4j 2 events into PostgreSQL database via JDBC >>> appender with datasource (com.jolbox.bonecp.BoneCPDataSource). >>> >>> This data source uses JDBC driver for PostgreSQL >>> (postgresql-9.2-1003.jdbc4.jar) but there isn't implemented >>> method org.postgresql.jdbc4.Jdbc4PreparedStatement.setNString(int, String) >>> which is called from Log4j 2. >>> >>> Is there some another way how to use Log4J database appender with >>> PostgreSQL database? >>> >>> Thank you for suggestions how to solve this issue. >>> >>> M. >> > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
