Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Remove username & password from code

...

Code Block
java
java
borderStylesolid
titleDBManagerBean.java
	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;
	}

...