📄 _resultset.java
字号:
package com.holpe.database;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.ResultSet;
/**
* 结果集合的接管,用于处理字符集的转码
* @author liuxb
*/
public class _ResultSet implements InvocationHandler {
private ResultSet rs;
private boolean decode;
public _ResultSet(ResultSet rs, boolean decode) {
this.rs = rs;
this.decode = decode;
}
/**
* 获取ResultSet的代理
* @return
*/
public ResultSet getResultSet() {
Class[] infs = rs.getClass().getInterfaces();
if(infs==null||infs.length==0)
infs = IRS;
return (ResultSet)Proxy.newProxyInstance(
rs.getClass().getClassLoader(), infs, this);
}
public Object invoke(Object proxy, Method m, Object args[]) throws Throwable
{
Object res = null;
String method = m.getName();
if (decode && GETSTRING.equals(method))
try {
String result = (String) m.invoke(rs, args);
if (result != null)
res = new String(result.getBytes("8859_1"));
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
try {
res = m.invoke(rs, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
return res;
}
private final static Class[] IRS = new Class[]{ResultSet.class};
private static final String GETSTRING = "getString";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -