我用的是mysql 8.0所以将 com.mysql.jdbc.Driver 改为com.mysql.cj.jdbc.Driver了。
代码除了上面的改动没有进行其他改动。
eclipse显示以下提示
严重: JDBC Driver class not found: com.mysql.cj.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:397)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1933)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
at com.mr.contact.hibernate.HibernateInitialize.rebuildSessionFactory(HibernateInitialize.java:54)
at com.mr.contact.hibernate.HibernateInitialize.getSession(HibernateInitialize.java:37)
at com.mr.contact.dao.DAOimpl.selectAllUser(DAOimpl.java:191)
at frame.MainFrame.main(MainFrame.java:22)
创建会话工厂失败
org.hibernate.HibernateException: JDBC Driver class not found: com.mysql.cj.jdbc.Driver
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:397)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1933)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
at com.mr.contact.hibernate.HibernateInitialize.rebuildSessionFactory(HibernateInitialize.java:54)
at com.mr.contact.hibernate.HibernateInitialize.getSession(HibernateInitialize.java:37)
at com.mr.contact.dao.DAOimpl.selectAllUser(DAOimpl.java:191)
at frame.MainFrame.main(MainFrame.java:22)
Caused by: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
... 10 more
Exception in thread "main" java.lang.NullPointerException
at com.mr.contact.dao.DAOimpl.selectAllUser(DAOimpl.java:193)
at frame.MainFrame.main(MainFrame.java:22)