📄 jmdboresultsetapc.java
字号:
package jm.dbo;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import jm.util.JM2DArray;
import jm.util.JMEntity;
import jm.util.JMMap;
import jm.util.JMUtility;
import jm.util.JMVal;
import jm.util.JMVector;
/**
* DBApc
* @author fu_changyong(1shome)
* @see jdk1.5.2
* @version 1.5.2.2
*/
@SuppressWarnings("unchecked")
public class JMDBOResultSetApc {
public static final String CLASS_NAME = "ResultSetApc";
/**
* ��ѯ���浽JM2DArray��
* @param ret
* @return
* @throws Exception
*/
public static synchronized JM2DArray getResultData (ResultSet ret) throws Exception {
// ����ʂ��荞��
ResultSetMetaData oMeta = ret.getMetaData();
int iColCount = oMeta.getColumnCount();
JM2DArray oResult = new JM2DArray("DBResult", true);
if (ret == null)
return oResult;
while (ret.next()) {
for (int iCol = 1; iCol <= iColCount; iCol++) {
// �J��������擾
String sColName = oMeta.getColumnName(iCol);
int iType = oMeta.getColumnType(iCol);
if (iType == Types.LONGVARCHAR ||
iType == Types.VARCHAR ||
iType == Types.CHAR) {
String sValue = ret.getString(iCol);
oResult.addItem(sColName, sValue);
} else if (iType == Types.NUMERIC ||
iType == Types.DECIMAL) {
String sValue = ret.getString(iCol);
oResult.addItem(sColName, new BigDecimal(sValue));
} else if (iType == Types.BOOLEAN) {
boolean bValue = ret.getBoolean(iCol);
if (bValue || !ret.wasNull())
oResult.addItem(sColName, bValue);
else
oResult.addItem(sColName, JMVal.BOOLEAN_NULL);
} else if (iType == Types.TINYINT) {
byte yValue = ret.getByte(iCol);
if (yValue != (byte) 0 || !ret.wasNull())
oResult.addItem(sColName, yValue);
else
oResult.addItem(sColName, JMVal.BYTE_NULL);
} else if (iType == Types.SMALLINT) {
short hValue = ret.getShort(iCol);
if (hValue != (short) 0 || !ret.wasNull())
oResult.addItem(sColName, hValue);
else
oResult.addItem(sColName, JMVal.SHORT_NULL);
} else if (iType == Types.INTEGER) {
int iValue = ret.getInt(iCol);
if (iValue != 0 || !ret.wasNull())
oResult.addItem(sColName, iValue);
else
oResult.addItem(sColName, JMVal.INT_NULL);
} else if (iType == Types.BIGINT) {
long lValue = ret.getLong(iCol);
if (lValue != 0L || !ret.wasNull())
oResult.addItem(sColName, lValue);
else
oResult.addItem(sColName, JMVal.LONG_NULL);
} else if (iType == Types.DOUBLE) {
double dValue = ret.getDouble(iCol);
if (dValue != 0.0D || !ret.wasNull())
oResult.addItem(sColName, dValue);
else
oResult.addItem(sColName, JMVal.DOUBLE_NULL);
} else if (iType == Types.FLOAT || iType == Types.REAL) {
float fValue = ret.getFloat(iCol);
if (fValue != 0.0F || !ret.wasNull())
oResult.addItem(sColName, fValue);
else
oResult.addItem(sColName, JMVal.FLOAT_NULL);
} else if (iType == Types.TIMESTAMP) {
Timestamp oTstmp = ret.getTimestamp(iCol);
if (oTstmp != null)
oResult.addItem(sColName,
new java.util.Date(oTstmp.getTime()));
else
oResult.addItem(sColName, (java.sql.Timestamp)null);
} else if (iType == Types.DATE) {
java.util.Date oDate = ret.getDate(iCol);
if (oDate != null)
oResult.addItem(sColName,
new java.util.Date(oDate.getTime()));
else
oResult.addItem(sColName, (java.util.Date)null);
} else if (iType == Types.TIME) {
Time oTime = ret.getTime(iCol);
if (oTime != null)
oResult.addItem(sColName,
new java.util.Date(oTime.getTime()));
else
oResult.addItem(sColName, (Time)null);
} else if (iType == Types.BINARY ||
iType == Types.VARBINARY) {
byte[] yValues = ret.getBytes(iCol);
oResult.addItem(sColName, yValues);
} else {
String sValue = ret.getString(iCol);
oResult.addItem(sColName, sValue);
}
}
oResult.nextRow();
}
return oResult;
}
/**
* ��ѯ���浽JMVector<JMEntity>��
* @param ret
* @param tableName
* @return
* @throws Exception
*/
public static synchronized JMVector getResultListData (ResultSet ret,String tableName) throws Exception {
JMEntity inClass = null;
JMMap data = null;
// ����ʂ��荞��
ResultSetMetaData oMeta = ret.getMetaData();
int iColCount = oMeta.getColumnCount();
JMVector oResult = new JMVector(50);
if (ret == null)
return oResult;
//System.out.println("tableName==="+tableName);
while (ret.next()) {
inClass = (JMEntity)Class.forName(tableName).newInstance();
data = new JMMap();
//��õ������
for (int iCol = 1; iCol <= iColCount; iCol++) {
data.put(oMeta.getColumnName(iCol),ret.getString(iCol));
}
//System.out.println("data==="+data);
//���浽Entity
{
JMUtility.reflectIntoEntity(inClass,data);
oResult.add(inClass);
}
}
//System.out.println("oResult==="+oResult);
return oResult;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -