插入部分代码
if(s.equals("出售")){
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myjava", "root", "sa");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into sale values('"+store+"','"+pro+"',"+price+","+quantity+","+total+");"); con.close();
}
catch(Exception e){
System.out.println("connect fail");
}
}
//查询部分代码
else if(s.equals("当天销售记录")){
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myjava", "root", "sa");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from sale;");
while(rs.next()){
System.out.print("连锁店:"+rs.getString(1)+" ");
System.out.print("商品:"+rs.getString(2)+" ");
System.out.print("单价:"+rs.getInt(3)+" ");
System.out.print("数量:"+rs.getInt(4)+" ");
System.out.println("总价:"+rs.getInt(5)+" ");
}
con.close();
}
catch(Exception e){
System.out.print("查询失败");
}
}
运行后查询结果,如果有中文的部分则为乱码,该如何修改
if(s.equals("出售")){
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myjava", "root", "sa");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into sale values('"+store+"','"+pro+"',"+price+","+quantity+","+total+");"); con.close();
}
catch(Exception e){
System.out.println("connect fail");
}
}
//查询部分代码
else if(s.equals("当天销售记录")){
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myjava", "root", "sa");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from sale;");
while(rs.next()){
System.out.print("连锁店:"+rs.getString(1)+" ");
System.out.print("商品:"+rs.getString(2)+" ");
System.out.print("单价:"+rs.getInt(3)+" ");
System.out.print("数量:"+rs.getInt(4)+" ");
System.out.println("总价:"+rs.getInt(5)+" ");
}
con.close();
}
catch(Exception e){
System.out.print("查询失败");
}
}
运行后查询结果,如果有中文的部分则为乱码,该如何修改
解决方案 »
- 求素数的问题
- ResultSet类的getObject(int i, Map<String, Class<?>> map)方法怎么用?
- 学习软件的疑惑!难道软件业只是做这些吗?
- SCJP中一个线程的问题
- 有关在application中使用cookie的问题!
- 请教一组问题,关于string/int/date/time之间的转化函数。
- java的服务器端,vb写的客户端,通过socket连接?????????/
- 怎样用log4j为某一指定的类日志
- 请问如何将byte数组转化为char数组或一个String
- 请问:用Apple中URLConnection.getOutputStream获得的输出流如何写进该URL文件?
- 乘法口诀编写
- 匿名内部类是否可以继承其它类?
可设置my.ini文件,将default-character-set设置为GBK
可设置my.ini文件,将default-character-set设置为GBK
[client]port=3306[mysql]default-character-set=gbk第二个:
# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf8
然后重启mysql服务即可.
最简单就是重新装Mysql,在最后几步的时候有选择“默认编码”,选择GBK就好了