Sorry, I made a mistake in the e-mail. I had the database set to the same name in both places.
My problem is actually opposite because I don't get any result where I use UTF-8 string as an input in the query. But I verified that I don't get correct results where using the query you provided neither. The link with the MySQL bug report might be helpful in resolving the problem so thanks for providing it.
Piotr
On 2012-04-01 19:50, Marcin Cieslak wrote:
Piotr Jagielskipiotr.jagielski@op.pl wrote:
Hello,
set my data source URL to the following in my Java code: jdbc:mysql://localhost/plwiki?useUnicode=true&characterEncoding=UTF-8
Please note you have "plwiki" here and you imported into "wiki". Assuming your .my.cnf is not making things difficult I ran a small Jython script to test:
$ jython Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) [OpenJDK 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0 Type "help", "copyright", "credits" or "license" for more information.
from com.ziclix.python.sql import zxJDBC d, u, p, v = "jdbc:mysql://localhost/wiki", "root", None, "org.gjt.mm.mysql.Driver" db = zxJDBC.connect(d, u, p, v, CHARSET="utf8") c=db.cursor() c.execute("select cl_from, cl_to from categorylinks where cl_from=61 limit 10") c.fetchone()
(61, array('b', [65, 110, 100, 111, 114, 97]))
(a,b) = c.fetchone() print b
array('b', [67, 122, -59, -126, 111, 110, 107, 111, 119, 105, 101, 95, 79, 114, 103, 97, 110, 105, 122, 97, 99, 106, 105, 95, 78, 97, 114, 111, 100, -61, -77, 119, 95, 90, 106, 101, 100, 110, 111, 99, 122, 111, 110, 121, 99, 104])
for x in b:
... try: ... print chr(x), ... except ValueError: ... print "%02x" % x, ... C z -3b -7e o n k o w i e _ O r g a n i z a c j i _ N a r o d -3d -4d w _ Z j e d n o c z o n y c h
array('b", [ ... ]) in Jython means that SQL driver returns an array of bytes.
It seems to me that array of bytes contains raw UTF-8, so you need to decode it into proper Unicode that Java uses in strings.
I think this behaviour is described in
http://bugs.mysql.com/bug.php?id=25528
Probably you need to play with getBytes() on a result object to get what you want.
//Saper
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l