日期:2014-05-20 浏览次数:20927 次
public static ArrayList<HashMap<String, Object>> getAttributeValue(String... param)
{
ResultSet resultSet = null;
PreparedStatement st = null;
Connection con = null;
ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> map = new HashMap<String, Object>();
for (int i = 0; i < param.length; i++)
{
String SQL = "SELECT " + param[i] + " FROM USER ";
con = getConnection();
System.out.println(1);
try
{
st = con.prepareStatement(SQL);
resultSet = st.executeQuery();
while (resultSet.next())
{
Object obj = resultSet.getObject(param[i]);
map.put(param[i], obj);
result.add(map);
map.clear();
}
} catch (SQLException e)
{
e.printStackTrace();
}
}
try
{
resultSet.close();
st.close();
con.close();
} catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}