MYSQL配置默认字符集是utf8,MyEclipse6.0设置默认字符集是utf8,数据库表中含中文。
Java code:
public class TestPolm{
public static void main(String args[]){
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Load driver failed��");
}
Connection con = null;
PreparedStatement ps=null;
ResultSet rs=null;
try {
con = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8", "root", "1111");
String sql = null;
try {
sql = new String("select * from ic_content_0002 where Title like '%窗口%'".getBytes(),"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
System.out.println(rs.getFetchSize());
while(rs.next()){
StringBuffer sb = new StringBuffer();
sb.append(rs.getString("Id"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.