如何返回查询结果ResultSet中int类型的数据
1个回答
展开全部
方法如下
protected String helper (ResultSet rs, int dataType, int col)
throws SQLException
{
String retVal = null;
Integer intObj;
// ask for data depending on the datatype
switch(dataType) {
case Types.DATE:
java.sql.Date date = rs.getDate(col);
retVal = date.toString();
break;
case Types.TIME:
java.sql.Time time = rs.getTime(col);
retVal = time.toString();
break;
case Types.TIMESTAMP:
java.sql.Timestamp timestamp = rs.getTimestamp(col);
retVal = timestamp.toString();
break;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
retVal = rs.getString(col);
break;
case Types.NUMERIC:
case Types.DECIMAL:
java.math.BigDecimal numeric = rs.getBigDecimal(col, 10);
retVal = numeric.toString();
break;
case Types.BIT:
boolean bit = rs.getBoolean(col);
Boolean boolObj = new Boolean(bit);
retVal = boolObj.toString();
break;
case Types.TINYINT:
byte tinyint = rs.getByte(col);
intObj = new Integer(tinyint);
retVal = intObj.toString();
break;
case Types.SMALLINT:
short smallint = rs.getShort(col);
intObj = new Integer(smallint);
retVal = intObj.toString();
break;
case Types.INTEGER:
int integer = rs.getInt(col);
intObj = new Integer(integer);
retVal = intObj.toString();
break;
case Types.BIGINT:
long bigint = rs.getLong(col);
Long longObj = new Long(bigint);
retVal = longObj.toString();
break;
case Types.REAL:
float real = rs.getFloat(col);
Float floatObj = new Float(real);
retVal = floatObj.toString();
break;
case Types.FLOAT:
case Types.DOUBLE:
double longreal = rs.getDouble(col);
Double doubleObj = new Double(longreal);
retVal = doubleObj.toString();
break;
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
byte[] binary = rs.getBytes(col);
retVal = new String(binary);
break;
}
return retVal;
}
protected String helper (ResultSet rs, int dataType, int col)
throws SQLException
{
String retVal = null;
Integer intObj;
// ask for data depending on the datatype
switch(dataType) {
case Types.DATE:
java.sql.Date date = rs.getDate(col);
retVal = date.toString();
break;
case Types.TIME:
java.sql.Time time = rs.getTime(col);
retVal = time.toString();
break;
case Types.TIMESTAMP:
java.sql.Timestamp timestamp = rs.getTimestamp(col);
retVal = timestamp.toString();
break;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
retVal = rs.getString(col);
break;
case Types.NUMERIC:
case Types.DECIMAL:
java.math.BigDecimal numeric = rs.getBigDecimal(col, 10);
retVal = numeric.toString();
break;
case Types.BIT:
boolean bit = rs.getBoolean(col);
Boolean boolObj = new Boolean(bit);
retVal = boolObj.toString();
break;
case Types.TINYINT:
byte tinyint = rs.getByte(col);
intObj = new Integer(tinyint);
retVal = intObj.toString();
break;
case Types.SMALLINT:
short smallint = rs.getShort(col);
intObj = new Integer(smallint);
retVal = intObj.toString();
break;
case Types.INTEGER:
int integer = rs.getInt(col);
intObj = new Integer(integer);
retVal = intObj.toString();
break;
case Types.BIGINT:
long bigint = rs.getLong(col);
Long longObj = new Long(bigint);
retVal = longObj.toString();
break;
case Types.REAL:
float real = rs.getFloat(col);
Float floatObj = new Float(real);
retVal = floatObj.toString();
break;
case Types.FLOAT:
case Types.DOUBLE:
double longreal = rs.getDouble(col);
Double doubleObj = new Double(longreal);
retVal = doubleObj.toString();
break;
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
byte[] binary = rs.getBytes(col);
retVal = new String(binary);
break;
}
return retVal;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询