📄 resultsets.java
字号:
package ConnectionDataBase;
import java.sql.ResultSet;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* 数据库结果集的代理类
* @author qibin
*/
public class ResultSets implements InvocationHandler
{
private ResultSet rs = null;
private boolean decode = false;
public ResultSets(ResultSet rs,boolean decode)
{
this.rs = rs;
this.decode = decode;
}
public ResultSet getResultSet()
{
Class[] interfaces = rs.getClass().getInterfaces();
if(interfaces==null||interfaces.length==0)
{
interfaces = new Class[1];
interfaces[0] = ResultSet.class;
}
ResultSet rs2 = (ResultSet)Proxy.newProxyInstance(rs.getClass().getClassLoader(),interfaces,this);
return rs2;
}
/**
* 结果getString方法
*/
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable
{
String method = m.getName();
if(decode && GETSTRING.equals(method))
{
try
{
String result = (String)m.invoke(rs,args);
if(result!=null)
return new String(result.getBytes("8859_1"));
return null;
}
catch(InvocationTargetException e)
{
throw e.getTargetException();
}
}
try
{
return m.invoke(rs, args);
}
catch(InvocationTargetException e)
{
throw e.getTargetException();
}
}
private final static String GETSTRING = "getString";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -