resultsetadapter.java
来自「Java Database connection pool」· Java 代码 · 共 113 行
JAVA
113 行
/* * PoolMan Java Object Pooling and Caching Library * Copyright (C) 1999-2001 The Code Studio * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * The full license is located at the root of this distribution * in the LICENSE file. */package com.codestudio.sql;import com.codestudio.util.JDBCPool;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.sql.Types;import java.util.Hashtable;/** * A data structure that conforms to ResultSet semantics * used to bridge the old SQLUtil Hashtable[] approach and * the new PoolManResultSet approach. */public class ResultSetAdapter { /* * Converts a ResultSet into the Hashtable array required * by SQLUtil. */ public static Hashtable[] convert(ResultSet res) throws SQLException { Hashtable[] results = new Hashtable[10]; ResultSetMetaData meta = PoolManResultSetMetaData.getCopy(res.getMetaData()); //## MC int cols = meta.getColumnCount(); int rowcount = 0; while (res.next()) { if (rowcount == results.length) { Hashtable[] temp = new Hashtable[results.length + 10]; for (int t = 0; t < results.length; t++) { temp[t] = results[t]; } results = temp; } Hashtable record = new Hashtable(1); for (int i = 1; i <= cols; i++) { Object value = null; try { switch (meta.getColumnType(i)) { //case Types.LONGVARBINARY: case Types.CHAR: try { // not sure about this fix, so be overly cautious value = new String(res.getBytes(i)); } catch (Exception _e) { value = res.getObject(i); } break; default: value = res.getObject(i); break; } } catch (Exception ee) { } if (value == null) value = new String(""); record.put(meta.getColumnLabel(i), value); } results[rowcount] = record; rowcount++; } JDBCPool.closeResources(null, res); res = null; // shrink the array Hashtable[] temp = null; for (int i = 0; i < results.length; i++) { if (results[i] == null) { temp = new Hashtable[i]; break; } else { temp = new Hashtable[results.length]; } } for (int i = 0; i < temp.length; i++) { temp[i] = results[i]; } results = temp; temp = null; return results; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?