/***
* 获取oracle数据字段信息(字段名,字段类型,字段长度,数字精度,是否为空)
* @param con
* @param table 表名
* @return
*/
public static Map<String,List<String>> getOracleColumn_info(Connection con,String table){
String sql="select COLUMN_NAME,DATA_TYPE,DATA_LENGTH,DATA_PRECISION,DATA_SCALE,NULLABLE from user_tab_columns where table_name =UPPER('"+table+"')";
Statement st = null;
Map<String,List<String>> map = new LinkedHashMap<String, List<String>>();
try{
st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
List<String> val = null;
while(rs.next()){
val = new ArrayList<String>();
String key = rs.getString("COLUMN_NAME"); //获取字段名
val.add(rs.getString("DATA_TYPE")); //获取数据类型
val.add(rs.getString("DATA_LENGTH")); //获取数据长度
val.add(rs.getString("DATA_PRECISION")); //获取数据长度
val.add(rs.getString("DATA_SCALE")); //获取数据精度
val.add(rs.getString("NULLABLE")); //获取是否为空
map.put(key, val);
}
}catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
return map;
}
/***
* 获取sql数据字段信息(字段名,字段类型,字段长度,数字精度,是否为空)
* @param con
* @param table
* @return
*/
public static Map<String,List<String>> getSQLColumn_info(Connection con,String table){
String sql="SELECT syscolumns.name COLUMN_NAME,systypes.name DATA_TYPE,syscolumns.length ,syscolumns.prec, syscolumns.scale ,syscolumns.isnullable FROM syscolumns, systypes WHERE syscolumns.xusertype = systypes.xusertype AND syscolumns.id = object_id('"+table+"')";
Statement st = null;
Map<String,List<String>> map = new LinkedHashMap<String, List<String>>();
try{
st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
List<String> val = null;
while(rs.next()){
val = new ArrayList<String>();
String key = rs.getString("COLUMN_NAME"); //获取字段名
val.add(rs.getString("DATA_TYPE")); //获取数据类型
val.add(rs.getString("length")); //获取数据长度
val.add(rs.getString("prec")); //获取数据长度
val.add(rs.getString("scale")); //获取数据精度
val.add(rs.getString("isnullable")); //获取是否为空
map.put(key, val);
}
}catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
return map;
}
* 获取oracle数据字段信息(字段名,字段类型,字段长度,数字精度,是否为空)
* @param con
* @param table 表名
* @return
*/
public static Map<String,List<String>> getOracleColumn_info(Connection con,String table){
String sql="select COLUMN_NAME,DATA_TYPE,DATA_LENGTH,DATA_PRECISION,DATA_SCALE,NULLABLE from user_tab_columns where table_name =UPPER('"+table+"')";
Statement st = null;
Map<String,List<String>> map = new LinkedHashMap<String, List<String>>();
try{
st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
List<String> val = null;
while(rs.next()){
val = new ArrayList<String>();
String key = rs.getString("COLUMN_NAME"); //获取字段名
val.add(rs.getString("DATA_TYPE")); //获取数据类型
val.add(rs.getString("DATA_LENGTH")); //获取数据长度
val.add(rs.getString("DATA_PRECISION")); //获取数据长度
val.add(rs.getString("DATA_SCALE")); //获取数据精度
val.add(rs.getString("NULLABLE")); //获取是否为空
map.put(key, val);
}
}catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
return map;
}
/***
* 获取sql数据字段信息(字段名,字段类型,字段长度,数字精度,是否为空)
* @param con
* @param table
* @return
*/
public static Map<String,List<String>> getSQLColumn_info(Connection con,String table){
String sql="SELECT syscolumns.name COLUMN_NAME,systypes.name DATA_TYPE,syscolumns.length ,syscolumns.prec, syscolumns.scale ,syscolumns.isnullable FROM syscolumns, systypes WHERE syscolumns.xusertype = systypes.xusertype AND syscolumns.id = object_id('"+table+"')";
Statement st = null;
Map<String,List<String>> map = new LinkedHashMap<String, List<String>>();
try{
st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
List<String> val = null;
while(rs.next()){
val = new ArrayList<String>();
String key = rs.getString("COLUMN_NAME"); //获取字段名
val.add(rs.getString("DATA_TYPE")); //获取数据类型
val.add(rs.getString("length")); //获取数据长度
val.add(rs.getString("prec")); //获取数据长度
val.add(rs.getString("scale")); //获取数据精度
val.add(rs.getString("isnullable")); //获取是否为空
map.put(key, val);
}
}catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
return map;
}