java查询数据库列名,输出需要编写的代码
时间:2021-07-01 10:21:17
帮助过:45人阅读
* 此方法是按照查询的结果集分离表名,所以是按顺序显示的
* @param tableName 数据库表名字
* @author txf
*/
public void getAllUsers( String tableName){
Connection conn =
DbConnection.getConn();
String sql="select * from "+tableName+" where rownum=1 "
;
PreparedStatement stmt=
null;
ResultSet rs=
null;
String name=""
;
try {
stmt=
conn.prepareStatement(sql);
rs=
stmt.executeQuery();
ResultSetMetaData rsmd =
rs.getMetaData() ;
for (
int i=1;i<=rsmd.getColumnCount() ;i++
){
name=
rsmd.getColumnName(i);
//if(s.get("memo")==null)pstmt.setString(13, ""); else pstmt.setString(13, s.get("memo").toString());
System.out.println("if(s.get(\""+name.toLowerCase()+"\")==null) pstmt.setString("+i+", \"\");else pstmt.setString("+i+", s.get(\""+name.toLowerCase()+"\").toString());"
);
//System.out.print(name+",");
//System.out.print("?,");
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DbConnection.close(rs, null, stmt, conn);
}
}
java查询数据库列名,输出需要编写的代码
标签:smd 通过 count() ble try catch param case exe