我哪里错了?我正在使用 Maven ProJect 使用 hibernate、JSP、SERVLET 制作 TODO 应用程序
Posted
技术标签:
【中文标题】我哪里错了?我正在使用 Maven ProJect 使用 hibernate、JSP、SERVLET 制作 TODO 应用程序【英文标题】:Where I am wrong? I am using Maven ProJect to make TODO application with hibernate ,JSP, SERVLET 【发布时间】:2021-08-08 07:08:22 【问题描述】:我的问题数据库连接 警告:SQL 错误:0,SQLState:08001 2021 年 5 月 18 日 8:08:09 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions 错误:找不到合适的驱动程序 我遇到了数据库连接问题。我正在使用 Eclispse 数据库 10g 雄猫 8.5 Ojdbc 14
我的代码是 hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_Class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@//localhost:1521/XE</property>
<property name="connection.username">system</property>
<property name="connection.password">system</property>
<property name="hibernate.default_schema">system</property>
<property name="dialect">org.hibernate.dialect.Oracle8iDialect</property>
<property name="hdm2ddl.auto">update</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<mapping class="com.entities.Note"/>
</session-factory>
</hibernate-configuration>
**SaveNoteServlet.java**
public class SaveNoteServlet extends HttpServlet
private static final long serialVersionUID = 1L;
public SaveNoteServlet()
super();
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
try
//title ,content fetch
String title=request.getParameter("title");
String content=request.getParameter("content");
Note note=new Note(title,content,new Date());
System.out.println(note);
//hibernate :save
Session ses=HibernateUtil.getSessionFactory().openSession();
System.out.println(ses);
Transaction t=ses.beginTransaction();
ses.save(note);
t.commit();
ses.close();
System.out.println("Tble created");
catch(Exception e)
**HIbernateUtil.java**
public class HibernateUtil
private static SessionFactory sessionFactory;
private static SessionFactory buildSessionFactory()
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().
configure("hibernate.cfg.xml").build();
Metadata metadata = new MetadataSources(standardRegistry).getMetadataBuilder().
build();
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
SessionFactory sessionFactory = sessionFactoryBuilder.build();
return sessionFactory;
public static SessionFactory getSessionFactory()
if (sessionFactory == null)
sessionFactory = buildSessionFactory();
return sessionFactory;
public static void close()
if(sessionFactory.isOpen())
sessionFactory.close();
Error code-
May 18, 2021 8:08:04 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core 5.4.5.Final
May 18, 2021 8:08:08 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations 5.1.0.Final
May 18, 2021 8:08:08 PM
org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
May 18, 2021 8:08:09 PM
org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [null] at URL []
May 18, 2021 8:08:09 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: password=****, driver_Class=oracle.jdbc.driver.OracleDriver, user=system
May 18, 2021 8:08:09 PM
org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
May 18, 2021 8:08:09 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
May 18, 2021 8:08:09 PM org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator initiateService
WARN: HHH000342: Could not obtain connection to query metadata : Cannot invoke "org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PoolState.getConnection()" because "this.state" is null
May 18, 2021 8:08:09 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle8iDialect
May 18, 2021 8:08:09 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 08001
May 18, 2021 8:08:09 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: No suitable driver found for
【问题讨论】:
【参考方案1】:我也遇到了同样的错误,但是在搜索了各种网站并尝试了他们的解决方案后,我知道您为 mysql 包含的依赖项应该在您的系统中安装了相同的版本。
在我的例子中,这种依赖可以正常工作-
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
您也可以尝试不同的版本。
【讨论】:
【参考方案2】:为什么连接 url 属性值留空?
以下是工作属性,试一试,如果有任何问题,请告诉我。
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.connection.password">tiger</property>
【讨论】:
在添加 url "jdbc:oracle:thin:@//localhost:1521/XE"后我也遇到了问题以上是关于我哪里错了?我正在使用 Maven ProJect 使用 hibernate、JSP、SERVLET 制作 TODO 应用程序的主要内容,如果未能解决你的问题,请参考以下文章
在我的 Maven 2 项目中,我应该将 weblogic-application.xml 放在哪里?