resend: bug:setBytes() works wron with charsetset is sjis
am 21.01.2003 03:14:12 von charles leeDescription:
I create one table with one blob column,
use jdbc to setBytes and getBytes to the column ,and
found out the value i get from the table is not the same
as what i had set into the table.(default charset is sjis)
when i change the my.ini 's charset,do not use sjis, it works well,
what i get is what i set.
I think the blob is binary data ,should not change value with
deferent charset.
How-To-Repeat:
mysql version:
mysql Ver 12.16 Distrib 4.0.7-gamma, for Win95/Win98 (i32)
OS:
win2000 with sp2 (English version ,but customize the region language
setting)
local : japanese , default language : japanese
my.ini
[mysqld]
default-character-set=sjis
Code: dbaccess.TestBinary.java
//--begin
/**
*@author charles j lee
*/
package dbaccess;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Statement;
class TestBinary {
public static void main(String[] args) throws
ClassNotFoundException,IOException,SQLException{
Class.forName("org.gjt.mm.mysql.Driver");
Connection connection =
DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tes t","root","") ;
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
//Connection connection =
DriverManager.getConnection("jdbc:odbc:local_test","root","" ) ;
//clear the old data and construct table with blob column
Statement st = connection.createStatement();
try{
st.execute("drop table testtable") ;
}
catch(SQLException ex){
}
st.execute("create table testtable(object blob)") ;
//set the binary data int to the table
PreparedStatement ps = connection.prepareStatement("insert into
testtable values(?)");
//write the binary data
byte[] b = {-84,-19,0,9,115};
System.out.println("initial byte data: ") ;
printByte(b) ;
ps.setBytes(1,b) ;
ps.executeUpdate();
ps.close();
//read the binary data
ResultSet rs = st.executeQuery("select * from testtable") ;
System.out.println("Get the byte data from db") ;
if(rs.next() ){
printByte(rs.getBytes(1)) ;
}
st.close();
connection.close();
}
/**
* out put the binary array,separate with /
* @param b
*/
static void printByte(byte b[])
{
System.out.println("{") ;
for(int i = 0; i < b.length ; i ++){
System.out.print((int)b[i]);
System.out.print("/") ;
if(i 10 == 0 && i != 0){
System.out.println();
}
}
System.out.println("}");
}
}
Synopsis:
Submitter-Id:
Originator: charles j lee
Organization: home
MySQL support: [none | licence | email support | extended email support ]
Severity: [non-critical | serious | critical ]
Priority: [low | medium | high ]
Category: [mysqld, mysql client, C, PHP, PERL, ...]
Class: [ sw-bug | doc-bug | change-request | support ]
Release: mysql-3.23.38
Exectutable: [mysqld, mysqld-shareware, mysqld-nt or mysqld-opt]
Environment: windows 2000 english version ,with service pack 2
System:
Compiler: VC++ 6.0
Architecture: i
____________________________________________________________ _____
ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger: http://messenger.msn.com/cn
------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail bugs-thread13539@lists.mysql.com
To unsubscribe, e-mail