如何动态的获取数据库里面的字段以…
2017-12-07 22:46
134 查看
private String getResult(String sql){
Connection conn=null;
ResultSet rs=null;
conn=
DBConnection.getConnection(Constants.DATABASE_PATH_STYLE);
PreparedStatement selectPS =
conn.prepareStatement(sql);
try {
rs =
selectPS.executeQuery();
} catch (SQLException e1)
{
// TODO
Auto-generated catch block
e1.printStackTrace();
}
ArrayList lstThemes=new
ArrayList();
try {
if(rs!=null){
int
colCount=rs.getMetaData().getColumnCount();
while(rs.next()){
HashMap
hm=new HashMap();
for(int
i=1;i<=rs.getMetaData().getColumnCount();i++){
String
colName=rs.getMetaData().getColumnName(i);
if("getValidColumnIndex".equals(colName))
{
continue;
}
hm.put(colName,rs.getString(colName));
}
lstThemes.add(hm);
}
}
} catch (SQLException e)
{
// TODO
Auto-generated catch block
e.printStackTrace();
}finally{
DBConnection.closeConnection(conn);
}
JSONArray json =
JSONArray.fromObject(lstThemes);
return json.toString();
}
Connection conn=null;
ResultSet rs=null;
conn=
DBConnection.getConnection(Constants.DATABASE_PATH_STYLE);
PreparedStatement selectPS =
conn.prepareStatement(sql);
try {
rs =
selectPS.executeQuery();
} catch (SQLException e1)
{
// TODO
Auto-generated catch block
e1.printStackTrace();
}
ArrayList lstThemes=new
ArrayList();
try {
if(rs!=null){
int
colCount=rs.getMetaData().getColumnCount();
while(rs.next()){
HashMap
hm=new HashMap();
for(int
i=1;i<=rs.getMetaData().getColumnCount();i++){
String
colName=rs.getMetaData().getColumnName(i);
if("getValidColumnIndex".equals(colName))
{
continue;
}
hm.put(colName,rs.getString(colName));
}
lstThemes.add(hm);
}
}
} catch (SQLException e)
{
// TODO
Auto-generated catch block
e.printStackTrace();
}finally{
DBConnection.closeConnection(conn);
}
JSONArray json =
JSONArray.fromObject(lstThemes);
return json.toString();
}
相关文章推荐
- 如何动态获取数据库里面的SQL
- 如何动态获取数据库表中的数据,数据库中的字段是在变化的
- 如何实现动态获取数据库中的字段
- android 里面 如何使用gson 快速获取类的所有字段名称,包括父类的
- 牛腩购物9 用户表设计/动软生成器/金钱字段decimal(18, 2)/ 注册的时候的前台js判断/后台代码判断/正则表达式软件/RegexBuddy/设置数据库字段的唯一性约束/如何获取控件在前台html的id值/如何将C#的后台正则换成js的正则
- 如何获取数据库字段名字
- SQLSERVER如何获取一个数据库中的所有表的名称、一个表中所有字段的名称
- [转]SQLSERVER如何获取一个数据库中的所有表的名称、一个表中所有字段的名称
- SQLSERVER如何获取一个数据库中的所有表的名称、一个表中所有字段的名称
- DataGrid动态生成模板列,模板列里面有一个TextBox,如何获取用户在TextBox里面输入的值啊?
- asp.net mvc 如何获取ViewBag里面的动态属性
- mysql+jsp,在jsp页面连接了数据库,已成功获取数据库字段,请问如何取到当前用户对应的信息
- 如何获取动态加载DLL 类里面的事件?
- SQLSERVER如何获取一个数据库中的所有表的名称、一个表中所有字段的名称
- SQLSERVER如何获取一个数据库中的所有表的名称、一个表中所有字段的名称
- SQLSERVER如何获取一个数据库中的所有表的名称、一个表中所有字段的名称
- SQLSERVER如何获取一个数据库中的所有表的名称、一个表中所有字段的名称
- 如何处理数据库动态字段
- SQL如何获取一个数据库中的所有表的名称、一个表中所有字段的名称