최대 절전 모드를 사용하여 테이블의 열 이름을 가져옵니다. 하나의 메서드를 만들고 내 테이블 이름을 해당 메서드로 전달하는 중이 예외 발생 중 : JDBC 유형 없음 방언 매핑 : -1 어느 하나를 탈 도와주세요 수최대 절전 모드를 사용하여 테이블의 열 이름을 가져올 수 없음
Mycode 아래:
다오 클래스 :
public class Dao {
public static void main(String[] args) {
Dao o=new Dao();
ArrayList list=o.getTableDesc("examtype");
System.out.println ("listlistlist"+list);
}
public ArrayList<String> getTableDesc(String tableName) {
System.out.println("getFieldNames:start" + tableName);
Object[] a;
List<Object[]> fieldNames = new ArrayList<Object[]>();
ArrayList<String> tabFieldNames = new ArrayList<String>();
Session ses = HibernateUtil.getSessionFactory().openSession();
try {
String queryStr = "DESCRIBE " + tableName;
fieldNames = (List<Object[]>) ses.createSQLQuery(queryStr).list();
System.out.println("fieldNamesfieldNames"+fieldNames);
for (int i = 0; i < fieldNames.size(); i++) {
a = fieldNames.get(i);
tabFieldNames.add(a[0].toString());
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("exception " + e);
} finally {
ses.close();
}
System.out.println("getFieldNames:end" + tabFieldNames.toString());
return tabFieldNames;
}
}
있는 hibernate.cfg.xml : 방언의
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306treamisdemo</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.connection.pool_size">30</property>
<property name="hibernate.jdbc.batch_size">100</property>
<!--<property name="hibernate.hbm2ddl.auto">update</property>-->
<property name="hibernate.connection.isolation">2</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
</session-factory>
</hibernate-configuration>
저는 MySQL 사용자가 아니지만이 방법이 도움이 될 수 있습니다. [http://edackoverflow.com/questions/12985533/getting-org-hibernate-mappingexception-no-dialect-mapping-for-jdbc-type- 4-exc) –