default-character-set=gbk ,setBytes() cause SQL syntax error.
Posted by: Zhao Bin
Date: December 15, 2004 03:07AM

hi all,
When I use "default-character-set=gbk" in my.ini file, and use below code, it was throw SQLException, like this:
java.sql.SQLException: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '歗 鉉毩n隲0n>?7煻?孴\\b(痢耟? ?8 錞圧??.鍾Q,蘧溎+?!穝+壟,/柕?伔Tb┍_?' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1371)
at net.risesoft.ZhaoBinTest.main(ZhaoBinTest.java:46)

here is the java code:
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/risenet?user=root&password=1234&useUnicode=true&characterEncoding=gbk");
String sql = "insert into test1 values('zs', ?);";
PreparedStatement stmt = conn.prepareStatement(sql);
byte[] buf = FileUtil.readFile("C:\\temp\\demo\\test.doc");
stmt.setBytes(1, buf);
stmt.execute();
stmt.clearParameters();
stmt.close();
conn.close();

But, when I change the characterEncoding to ISO8859_1 or latin1(also remove "default-character-set=gbk" in my.ini),it works fine. My native language is chinese, in my application must use gbk. how can I duel with it ?

Any suggestion is welcome.

thanks a lot.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.