困扰了我三四天,今天终于解决了 哈哈 主要是一个地方
在mysql下面的my.ini里要把原来的default-character-set=latin1改成 default-character-set=gb2312
其它的连接工具也要做这个工作 下面把一个网友的测试页放上来
CREATE TABLE `test` (
`test` varchar(11) NOT NULL,
`id` int NOT NULL auto_increment,
PRIMARY KEY (`test`,`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<HTML>
<BODY>
<%
Connection con;
Statement stmt;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver");
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
String dbUrl="jdbc:mysql://localhost:3306/phonedb?useUnicode=true&characterEncoding=GBK";
String dbUser="dbuser";
String dbPwd="1234";
con=java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
stmt=con.createStatement();
String title1="科学";
String ins="insert into test(test) values('"+title1+"')";
//out.print(ins);
stmt.execute(ins);
%>
</BODY>
</HTML>