我的表是这么建的
CREATE TABLE test (
Id int(6) NOT NULL auto_increment,
name varchar(10) binary,
sex varchar(4) binary,
birthday date default '0000-00-00',
PRIMARY KEY (Id)
) DEFAULT CHARSET=GBK;
CREATE TABLE test (
Id int(6) NOT NULL auto_increment,
name varchar(10) binary,
sex varchar(4) binary,
birthday date default '0000-00-00',
PRIMARY KEY (Id)
) DEFAULT CHARSET=GBK;
String.getByte()方法
在my.ini中设置mysql的编码就行了
#Set the default character set.
default-character-set=gb2312
在my.ini中设置mysql的编码就行了
#Set the default character set.
default-character-set=gb2312这个我也看到过,可是我没有找到my.ini文件
我用的mysql5.0
String str_sex="男";
str_name = new String(str_name.getBytes(),"8859_1");
str_sex = new String(str_sex.getBytes(),"8859_1");
// SQL statement is here
String sql="insert into student (id,name,sex,birthday) values (20012050101,?,?,1983/02/01);";
PreparedStatement stmt=con.prepareStatement(sql);
stmt.setString(1,str_name);
stmt.setString(2,str_sex);
stmt.addBatch();
stmt.executeBatch();
my.ini是这样吗?#This File was made using the WinMySQLAdmin 1.4 Tool
#2004-6-18 7:27:51#Uncomment or Add only the keys that you know how works.
#Read the MySQL Manual for instructions[mysqld]
basedir=D:/mysql
#bind-address=10.68.13.36
datadir=D:/mysql/data
#language=D:/mysql/share/your language directory
#slow query log#=
#tmpdir#=
#port=3306
#set-variable=key_buffer=16M
#Set the default character set. default-character-set=gb2312
[WinMySQLadmin]
Server=D:/mysql/bin/mysqld-nt.exe
user=caixp
password=19780306