DESCRIBE TableName
缩写为:
DESC TableName
SHOW COLUMNS FROM TableName
select COLUMN_NAME from information_schema.columns where table_name='TableName'
也可以实现相同的功能
实战:
package com.ms.onlineexcel.dao.impl;
import com.ms.onlineexcel.dao.IExcelDao;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.*;
/**
* Created by lenovo on 2014/8/23.
*/
@Repository("excelDao")
public class ExcelDao implements IExcelDao {
@Autowired
private SessionFactory sessionFactory;
@Override
public List<String> getStudentData() {
Session session;
try {
session = sessionFactory.getCurrentSession();
} catch (Exception e) {
session = sessionFactory.openSession();
}
String getColumnSql = "SELECT COLUMN_NAME FROM information_schema.columns WHERE table_name='studentdata'";
List<String> excelColumnList = session.createSQLQuery(getColumnSql).list();
/* String getStudentDataSql = "SELECT * FROM studentdata";
List<Map<Object,Object>> studentDataList = session.createSQLQuery(getStudentDataSql).list();
另外开一个类来取。
*/
return excelColumnList;
}
}