简体   繁体   English

当我尝试使用JPA连接时是否需要mysql连接器?

[英]Is the mysql connector needed when I am trying to connect using JPA?

I have been fetching data from database to my JAVA program by using JDBC till now and I am doing so by creating a connection class and in that class I will use the DriverManager.getConnection() fnc, but as I am moving towards JPA I have learnt that a persistence.xml file is needed to connect to mysql. 到目前为止,我一直在使用JDBC将数据从数据库中提取到我的JAVA程序中,而我正在通过创建一个连接类来做到这一点,在该类中,我将使用DriverManager.getConnection()fnc,但是随着我朝着JPA迈进,了解到需要一个persistence.xml文件才能连接到mysql。 In the project where I am using JPA am i supposed to create this connection class again and should I place the connector jar file in the project where I will be using jpa. 在我使用JPA的项目中,我应该再次创建此连接类,并且应该将连接器jar文件放置在将要使用jpa的项目中。

Excuse my unawarness of the concept I am still in the learning phase.Any help is appreciated as I am new to this. 对这个概念我不为所动,仍然处于学习阶段,对我的新帮助将不胜感激。

Here Need to clear for you. 这里需要为您清除。

  1. JPA is a specification. JPA是一个规范。 Different ORM technology uses it. 不同的ORM技术使用它。 Like hibernate implemented JPA specification. 就像hibernate实现的JPA规范一样。 Specification defines how it works. 规范定义了它的工作方式。

  2. Hibernate is ORM technology. 休眠是ORM技术。 It binds Your Plain Java Object (Entity) to your database tables. 它将您的纯Java对象(实体)绑定到数据库表。 And table's column will be Entity's field. 表的列将是实体的字段。 Like Table has Id column of number type, in entity it will be Long id; 就像Table具有数字类型的ID列一样,在实体中它将为Long id; . table name will be entity name or others that is defined in hibernate docs. 表名将是实体名称或在休眠文档中定义的其他名称。

  3. 3rd One is Database connector. 第三个是数据库连接器。 Yes there is different types of connector for every database. 是的,每个数据库都有不同类型的连接器。 like for mysql connector is using to connect your implemented code with databases. 就像mysql连接器用于将已实现的代码与数据库连接一样。 You can think Its a communication Layer for database and your code. 您可以认为它是数据库和您的代码的通信层。 Your code is communicating with database through this connector. 您的代码正在通过此连接器与数据库进行通信。

Hope now you get concept why mysql connector is needed to connect. 希望现在您能明白为什么需要mysql连接器进行连接。 Happy Coding :) 快乐编码:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用JSP页面连接到MySql时出现错误 - I am getting error when trying to connect to MySql using JSP page 为什么在使用JPA执行基本mySQL搜索时出现此错误? - Why am I getting this error when carrying out a basic mySQL search using JPA? 尝试使用 JPA 将数据插入 MySQL 数据库时,抛出异常:列“billing_address”不能为空 - When trying to use JPA to insert data into a MySQL Database, i am thrown the exception: Column 'billing_address' cannot be null 当我尝试使用JSch或Socket连接到频道时,我感到困惑和困惑? - I am confused and stuck when trying to connect to a channel using JSch or Socket? 我是Java的新手,并且尝试连接到derby数据库。 我正在使用netbeans 7.4 - I am a newbie with java and I am trying to connect to a derby database. I am using netbeans 7.4 我正在尝试使用休眠xml映射连接到mysql数据库,但出现此错误 - I am trying to connect to a mysql database with hibernate xml mapping but I am getting this error 当我尝试添加 mysql 连接器依赖项时出现错误 - I am getting an error when i try to add mysql connector dependency 我正在使用 spring 启动并尝试连接 Apache Phoenix - i am using spring boot and trying to connect Apache Phoenix 我正在尝试使用jconsole连接到具有身份验证的JMX,但我无法这样做。 但是我无需身份验证就可以连接它 - I am trying to connect to JMX with authentication using jconsole, but I am not able to do so. But I am able to connect it without authentication 无法使用Jython和mysql.connector模块连接到mysql数据库 - Not able to connect to mysql database using Jython with mysql.connector module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM