錯誤提示:沒(méi)有設置數據庫方言(dialect)
錯誤原因:其實(shí)并不是你沒(méi)有對dialect進(jìn)行設置,而是你在使用hibernate的時(shí)候,沒(méi)有調用配置文件,導致系統不能讀出dialect信息。
解決辦法:
方法一:
Configuration config = new Configuration();
SessionFactory sf=config.configure().buildSessionFactory();
Session s=sf.openSession();
而不是:(注意有顏色部分)
Configuration config = new Configuration();
SessionFactory sf=config.buildSessionFactory();
Session s=sf.openSession();
方法二:
寫(xiě)一個(gè) hibernate.properties文件 放在src目錄中,基本內容如下:
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.password=sa
hibernate.connection.url=jdbc\:mysql\數據庫url
hibernate.connection.username=root
hibernate.dialect=org.hibernate.dialect.MySQLDialect
堅持