java读取mysql数据库latin1避免乱码方法
写入时,先做encode:
public static String encode(String src) {
String result = null;
try {
result = new String(src.getBytes("gbk"), "ISO-8859-1");
} catch (UnsupportedEncodingException uee) {
System.err.println(uee);
}
return result;
}
读出时,再做decode:
public static String decode(String src) {
String result = null;
try {
result = new String(src.getBytes("ISO-8859-1"), "gbk");
} catch (UnsupportedEncodingException uee) {
System.err.println(uee);
}
return result;
}
连接时不需要指定字符集
相关文档:
package com.citycollege.stw;
public class testreplace {
public static final String replace( String line, String oldString, String newString )
{
if (line == null)
{
return null ......
Class.forName(xxx.xx.xx) 返回的是一个类 首先你要明白在java里面任何class都要装载在虚拟机上才能运行。这句话就是装载类用的(和new 不一样,要分清楚)。
至于什么时候用,你可以考虑一下这个问题,给你一个字符串变量,它代表一个类的包名和类名,你怎么实例化它?只有你提到的这个方法了,不过要再加一点。
A a = ( ......
http://www.javaalmanac.com
- Java开发者年鉴一书的在线版本. 要想快速查到某种Java技巧的用法及示例代码, 这是一个不错的去处.
http://www.onjava.com
- O'Reilly的Java网站. 每周都有新文章.
http://java.sun.com
- 官方的Java开发者网站 - 每周都有新文章发表.
http://www.developer.com/java
-
由Ga ......
1. 给root加密码:/usr/bin/mysqladmin -u root password 123456
2. 导出:mysqldump -u root -p dbname > file.sql
3. 导入:mysql -u root -p dbname < backup-file.sql
4. 授权:grant all on *.* to root@"%" identified by "密码";
5. 收回权限:revoke all privileges on *.* from root@"%";
6. 登录:mys ......