📄 convertutil.java
字号:
package org.speedframework.db.executor;
//~--- non-JDK imports --------------------------------------------------------
import org.speedframework.exception.SpeedFrameworkException;
import org.speedframework.utilities.PropertiesUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.sql.*;
/**
* <p/>
* Title: SpeedFrameworkWork??��???
* </p>
* <p/>
* Description:???????????????
* </p>
* <p/>
* Copyright: Copyright (c) 2005
* </p>
* <p/>
* Company: SpeedFrameworkWork
* </p>
*
* @author ????? ?��:13926047208
* @version 1.1beta
*/
public class ConvertUtil
{
/**
* Constructs ...
*
*/
public ConvertUtil() {}
/**
* importData
*
* @param ps PreparedStatement
* @param index int
* @param obj Object
* @param isUpdate
* @throws SQLException
*/
public static void importData(PreparedStatement ps, int index, Object obj, boolean isUpdate) throws SQLException {
if (obj != null) {
if ((obj instanceof String) && (obj.toString().length() < 500)) {
ps.setString(index, obj.toString());
}
if ((obj instanceof String) && (obj.toString().length() > 500)) {
ps.setCharacterStream(index,
new InputStreamReader(new ByteArrayInputStream(obj.toString().getBytes())),
obj.toString().length());
}
if (obj instanceof Integer) {
ps.setInt(index, ((Integer) obj).intValue());
}
if (obj instanceof Long) {
ps.setLong(index, ((Long) obj).longValue());
}
if (obj instanceof Short) {
ps.setShort(index, ((Short) obj).shortValue());
}
if (obj instanceof Boolean) {
ps.setBoolean(index, ((Boolean) obj).booleanValue());
}
if (obj instanceof BigDecimal) {
ps.setBigDecimal(index, (BigDecimal) obj);
}
if (obj instanceof Double) {
ps.setDouble(index, ((Double) obj).doubleValue());
}
if (obj instanceof Float) {
ps.setFloat(index, ((Float) obj).floatValue());
}
if (obj instanceof Date) {
ps.setDate(index, new java.sql.Date(((Date) obj).getTime()));
}
if (obj instanceof Byte) {
ps.setByte(index, ((Byte) obj).byteValue());
}
if ((obj instanceof Blob) && isUpdate) {
ps.setBlob(index, ((Blob) obj));
}
if ((obj instanceof Blob) &&!isUpdate) {
ps.setBinaryStream(index, ((Blob) obj).getBinaryStream(), (int) ((Blob) obj).length());
}
if ((obj instanceof Clob) && isUpdate) {
ps.setClob(index, ((Clob) obj));
}
if ((obj instanceof Clob) &&!isUpdate) {
ps.setCharacterStream(index, ((Clob) obj).getCharacterStream(), (int) ((Clob) obj).length());
}
if (obj instanceof Time) {
ps.setTime(index, ((Time) obj));
}
if (obj instanceof Timestamp) {
ps.setTimestamp(index, ((Timestamp) obj));
}
} else {
ps.setNull(index, Types.INTEGER);
}
}
/**
* ?????????????
*
* @param rs
* @param columnName
* @param voClass
* @return
* @throws SQLException
* @throws InstantiationException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws SpeedFrameworkException
*/
public static Object outPortData(ResultSet rs, String columnName, Class voClass)
throws SQLException, InstantiationException, NoSuchMethodException, InvocationTargetException,
IllegalAccessException, SpeedFrameworkException {
Object fieldValue = null;
// Object ObjValue=null;
// ObjValue= rs.getObject(columnName);
if (columnName != null) {
if ("rownum".equals(columnName)) {
fieldValue = new Long(rs.getLong(columnName));
} else if ("rownum_".equals(columnName)) {
fieldValue = new Long(rs.getLong(columnName));
} else if ("count_".equals(columnName)) {
fieldValue = new Long(rs.getLong(columnName));
} else {
// if (rs.getObject(columnName) != null) {
Class propertyClass = PropertiesUtil.getPropertyType(voClass.newInstance(), columnName);
if (propertyClass == null) {
throw new SpeedFrameworkException("Property not found " + columnName);
}
String classType = propertyClass.getName();
if (classType.equals("java.lang.Integer") || classType.equals("int")) {
fieldValue = new Integer(rs.getInt(columnName));
} else if (classType.equals("java.lang.Long") || classType.equals("long")) {
fieldValue = new Long(rs.getLong(columnName));
} else if (classType.equals("java.math.BigDecimal")) {
fieldValue = rs.getBigDecimal(columnName);
} else if (classType.equals("java.lang.String")) {
fieldValue = rs.getString(columnName);
} else if (classType.equals("java.util.Date")) {
java.sql.Date date = rs.getDate(columnName);
if (date != null) {
fieldValue = new java.util.Date(date.getTime());
} else {
fieldValue = null;
}
} else if (classType.equals("java.sql.Time")) {
java.sql.Time date = rs.getTime(columnName);
if (date != null) {
fieldValue = date;
} else {
fieldValue = null;
}
} else if (classType.equals("java.sql.Timestamp")) {
java.sql.Timestamp date = rs.getTimestamp(columnName);
if (date != null) {
fieldValue = date;
} else {
fieldValue = null;
}
} else if (classType.equals("java.lang.Double") || classType.equals("double")) {
fieldValue = new Double(rs.getDouble(columnName));
} else if (classType.equals("java.lang.Float") || classType.equals("float")) {
fieldValue = new Float(rs.getFloat(columnName));
} else if (classType.equals("java.lang.Byte") || classType.equals("byte")) {
fieldValue = new Byte(rs.getByte(columnName));
} else if (classType.equals("java.lang.Boolean") || classType.equals("boolean")) {
fieldValue = new Boolean(rs.getBoolean(columnName));
} else if (classType.equals("java.lang.Char") || classType.equals("char")) {
fieldValue = new java.lang.Character(rs.getString(columnName).charAt(0));
} else if (classType.equals("java.sql.Blob") || classType.equals("Blob")) {
fieldValue = rs.getBlob(columnName);
} else if (classType.equals("java.sql.Clob") || classType.equals("Clob")) {
fieldValue = rs.getClob(columnName);
}
}
// }
}
return fieldValue;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -