标签:smd 通过 count() ble try catch param case exe
程序开发中有时候会有一些列特别多的数据库表,这时候一个一个绑定t数据列就比较麻烦,可以通过查询数据库的列名,直接输出出来,可以通过输出的列,添加不同的内容输出
/** * 此方法是按照查询的结果集分离表名,所以是按顺序显示的 * @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); } }
标签:smd 通过 count() ble try catch param case exe
原文地址:http://www.cnblogs.com/-txf-/p/6520428.html