/*Statement statement = null;
Connection disconnect = null;
ResultSet resultSet = null;
try {
disconnect = getSession().disconnect();
statement = disconnect.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
resultSet = statement.executeQuery(sql);
ResultSetMetaData metaData = resultSet.getMetaData();
for (int i = 0; i < metaData.getColumnCount(); i++) {
System.out.println("获取到的数据ziduan字段名:" + metaData.getColumnName(i));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (statement != null) {
try {
if (resultSet != null) {
resultSet.close();
}
statement.close();
disconnect.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}*/
// String[] namedParameters = getSession().createSQLQuery(sql).getNamedParameters();
// System.out.println("namedParameters = " + Arrays.toString(namedParameters));

以上代码应该可行,但是我用的时候包异常,好像是连接的问题,有知道原因的大神请指点一下.

 

String sql = "SELECT * FROM " + tableName;/* + " WHERE Recid=" + queryParameters*/
List<Map<String, Object>> list = getSession().createSQLQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
System.out.println("获取到的数据list:" +list);

这三行代码可以输出list集合,key是字段名称,value是值   <正好是我想要的>

/*String sql = "SELECT * FROM " + tableName;
List list = getSession().createSQLQuery(sql).list();
for (int i = 0; i < list.size(); i++) {
//这里要用Object[]接收查出来的list中每一条数据
Object[] obj = (Object[]) list.get(i);
System.out.println("获取到的数据:13" + Arrays.toString(obj));
}*/

如果只是查询数据的话,以上几行代码即可.