...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
public Map getTableList(String poolName, String userName, String password) throws SQLException { tableMap = new HashMap(); if(poolMap.containsKey(poolName)){ DataSource ds = (DataSource)poolMap.get(poolName); Connection con = null; try { if(userName != null || password != null){ con = ds.getConnection(); }else { con = ds.getConnection(userName, password); } DatabaseMetaData metaData = con.getMetaData(); String[] tableTypes = {"TABLE"}; ResultSet rs = metaData.getTables(null, null, null, tableTypes); while(rs.next()){ String schemaName = rs.getString("TABLE_SCHEM"); String tableName = rs.getString("TABLE_NAME"); ArrayList tableList = null; if(tableMap.containsKey(schemaName)){ tableList = (ArrayList)tableMap.get(schemaName); tableList.add(tableName); }else { tableList = new ArrayList(); tableList.add(tableName); } tableMap.put(schemaName, tableList); } } catch (SQLException e) { throw e; }finally { if(con != null){ try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } } } return tableMap; } |
...