Connection conn=null;
try {
conn = DbBean.getConnection("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/test","root","123");
System.out.println("Connection Success");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String sql="insert into my values(11,'北京','北京')";
DBOpera.ExeSql(conn, sql);
System.out.println("Insert OK!");
String add=util.getContent("Select add form my t where t.name='北京'",conn);
System.out.println("+++++"+add);
DBOpera.close(conn);插入没有问题:
Connection Success
ExeSQL:insert into my values(11,'北京','北京')
Insert OK! 但Select的时候 中文变成乱码了。。
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 'add form my t where t.name='±±??'' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1026)
try {
conn = DbBean.getConnection("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/test","root","123");
System.out.println("Connection Success");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String sql="insert into my values(11,'北京','北京')";
DBOpera.ExeSql(conn, sql);
System.out.println("Insert OK!");
String add=util.getContent("Select add form my t where t.name='北京'",conn);
System.out.println("+++++"+add);
DBOpera.close(conn);插入没有问题:
Connection Success
ExeSQL:insert into my values(11,'北京','北京')
Insert OK! 但Select的时候 中文变成乱码了。。
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 'add form my t where t.name='±±??'' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1026)
"character_set_connection","gb2312"
"character_set_database","gbk"
"character_set_filesystem","binary"
"character_set_results","gb2312"
"character_set_server","gbk"
"character_set_system","utf8"
"character_sets_dir","C:\\Program Files\\MySQL\\MySQL Server 5.1\\share\\charsets\\"
SET NAMES GBK
再插入记录
插入记录没有问题select 条件带中文就有问题。。
插入记录、取出记录
MySQL 中文显示乱码