0

I can connect to the embedded h2 database, but am confused about the correct syntax for connecting to a mysql database named 'test1'. For example, I would like to know what to substitute in the pom.xml, web.xml and persistence.xml files instead of the h2 terminology. I'm using mysql 5.7.27, with mysql-connector-java-8.0.27.jar in my src/main/resources/META-INF/lib folder. My url is jdbc:mysql://localhost:3306/test1

pom.xml - what to use for groupId and artifactId

   <dependency>
     <groupId>com.h2database</groupId>
     <artifactId>h2></artifactId>
     <version>1.4.200</version>
   </dependency>

web.xml - what to use for name and class

   <data-source>
     <name>java:global/DataSourceName>
     <class-name>org.h2.jdbcx.JdbcDataSource</class-name>
     <url>jdbc:h2:mem;DB_CLOSE_DELAY=-1</url>
   </data-source>

persistence.xml - does this need to change

   <persistence-unit name="PersistenceUnitName" 
     transaction-type="JTA">
     <jta-data-source>java:global/DataSourceName</jta-data-source>
     <properties>
       <property 
          name="javax.persistence.schema-generation.database.action"
          value="none" />
     </properties>
   </persistence.unit>
  </persistence>
greg-449
  • 109,219
  • 232
  • 102
  • 145
Ron
  • 67
  • 4
  • I don't know how to change it, or how it is supposed to look – Ron Jan 07 '22 at 22:51
  • Not sure how to fix it – Ron Jan 07 '22 at 22:53
  • *"mysql-connector-java-8.0.27.jar in my src/main/resources/META-INF/lib folder"* where exactly did you read/learn that this would be the correct approach? This misinformation needs to be corrected. – BalusC Jan 10 '22 at 10:08
  • Not sure, but I've removed this jar file, and added a dependency to the pom.xml. – Ron Jan 10 '22 at 20:51

1 Answers1

0

follow this Guide to configure all things you need to connect to MySQL or MariaDB.Use the bellow configuration for MySQL.

- in step (1) use The right classname of MySQl DataSource as bellow:

datasource-classname="com.mysql.cj.jdbc.MysqlDataSource"

Ref: MySQL Doc - Configuration Properties

- In step (3) Add this in POM.XML:

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>x.y.z</version>
</dependency>

Ref: MySQL Doc - Installing MySQL Connector/J Using Maven

mtz1406
  • 75
  • 1
  • 10
  • I have tried to follow your instructions, but I must have misinterpreted something as attempts to run the project result in a 'file not found' message form the browser. – Ron Jan 10 '22 at 20:06
  • How to add more information? The comment section is not long enough. – Ron Jan 10 '22 at 20:53
  • try to edit your question to add more information or screenshots. – mtz1406 Jan 11 '22 at 02:21