查询表字段类型
来源:互联网 发布:淘宝网免费下载 编辑:程序博客网 时间:2024/05/01 18:31
* 根据表明查询字段类型
* */
private Map<String, Integer> queryFieldMap(String tableName, String dbName){
if(tableName == null || dbName == null){
return null;
}
Map<String, Integer> resultMap = new HashMap<String, Integer>();
Connection conn = null;
Statement stat = null;
ResultSet rs = null;
try {
conn = ConnectionPool.getInstance().getConnection(dbName);
stat = conn.createStatement();
rs = stat.executeQuery("select * from " + tableName + " where 1 = 0");
ResultSetMetaData rsmd = rs.getMetaData();
int count = rsmd.getColumnCount();
for(int index = 1; index <= count; index++){
String colName = rsmd.getColumnName(index).toLowerCase();
int colType = rsmd.getColumnType(index);
resultMap.put(colName, colType);
}
} catch (SQLException e) {
log.error(e.getMessage());
e.printStackTrace();
resultMap = null;
} finally {
try { rs.close(); } catch (Exception e) { e.printStackTrace(); }
try { stat.close(); } catch (Exception e) { e.printStackTrace(); }
try { conn.close(); } catch (Exception e) { e.printStackTrace(); }
}
return resultMap;
}
2.引用的地方:
fieldType = fieldTypeMap.get(fieldName.toLowerCase());
if(fieldType == java.sql.Types.VARCHAR){//String
PreStatSetValue.setString(pstmt, index + 1, fieldValue);
} else if(fieldType == java.sql.Types.INTEGER || fieldType == java.sql.Types.NUMERIC || fieldType == java.sql.Types.SMALLINT){//int
try{
PreStatSetValue.setInt(pstmt, index + 1, Integer.parseInt(fieldValue));
}catch(Exception e){
log.error("更新cssf_ts_statistics, 字段值设置错误:fieldName = " + fieldName + ", 要求类型:" + fieldType + ", 设置值:" + fieldValue);
PreStatSetValue.setInt(pstmt, index + 1, 0);
}
} else if(fieldType == java.sql.Types.DATE || fieldType == java.sql.Types.TIMESTAMP){//date
PreStatSetValue.setTimestamp(pstmt, index + 1, fieldValue);
}
- 查询表字段类型
- Oracle查询表字段和类型
- MySQL表字段类型
- oracle cols 查询表字段类型及长度 function
- 查找表字段的类型
- mysql更改表字段类型
- Teradata 修改表字段类型
- pgSql 修改表字段类型
- 查询表字段和注解
- 查询oracle表字段信息
- sql server 表字段查询
- oracle数据库查询表字段
- mysql查询表字段信息
- oracle查询表字段个数
- Yii关联表字段查询
- sql语句查询表字段
- SQL 查询表字段信息
- mysql查询表字段默认值
- java向线程中传递参数
- linux各文件夹的作用
- 山沟沟里的实业路(2)
- Managed Debugging Assistants (zz)
- IOS--UIScrollView delegate 协议-
- 查询表字段类型
- [cocos2d-x] --- CCNode类详解
- 看13位CEO、创始人和高管如何提高工作效率
- YII简单的文件下载
- ERP系统容灾方案析投入产出比例与维护管理成本分析
- C++开发者都应该使用的10个C++11特性
- 笔记
- MS是彻底抛弃makefile了,他新一代的build system 是MS Build.
- SDL2.0 ubuntu complie