0

The program versions I’m using are Apache Netbeans IDE 15, MySQL WorkBench 8.0 CE, Eclipse GlassFish 6.2.5 (build 6.x-b66-g0159b68 2022-02-12T17:39:59+0000). My drivers are mysql-connector-j-8.0.31 and mysql-connector-java-5.1.47.

Good day everyone, before you tell me this is a duplicate question let me explain you how it’s different. I first got this error in Glassfish Domain Admin Console when I checked the JDBC Connection Pool’s ping. I fixed the error but now I’m getting the error in my browser when I run the project. I have been watching this video series as a guide line for my own netbeans e commerce project but at 42:00 the teacher adds a DB Query Database but when I added this code to my index.jsp file I got this error message in my browser “jakarta.servlet.jsp.JspException: Unable to get connection, DataSource invalid: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: The connection property 'zeroDateTimeBehavior' only accepts values of the form: 'exception', 'round' or 'convertToNull'. The value 'CONVERT_TO_NULL' is not in this set." I have the jdbc/OkStore resource reference in web.xml. I changed the resource type to javax.sql.DataSource. I changed the datasource classname from com.mysql.jdbc.jdbc2.optional.MysqlDataSource to com.mysql.cj.jdbc.MysqlDataSource. I have deleted the old driver and downloaded the new one. Do you guys have any ideas to fix this? By the way I will be updating the post with failed solutions so that I don’t get repeats. https://www.youtube.com/watch?v=JlLGrqHSSjk&list=PLWS58wV27xi5AFrSfru26h4KWNMv1h2XA&index=16&ab_channel=CS.Math.Educator Error message

DB Query Database code in index.jsp file that caused the error message
<sql:query var="categories" dataSource="jdbc/OkStore">
        SELECT * FROM category
    </sql:query>

The jdbc/OkStore resource reference code in web.xml
<resource-ref>
    <description>Connects to database for OkStore application</description>
    <res-ref-name>jdbc/OkStore</res-ref-name>
    <res-type>javax.sql.ConnectionPoolDataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

List of failed solutions Glassfish - No suitable driver for mysql when trying to connect with datasource

java.sql.SQLException: No suitable driver found for CONNECTION_URL

Class name is wrong or classpath is not set for : com.mysql.jdbc.Driver

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found

JDBC converting Timestamp to NULL (zeroDateTimeBehavior issue)

I changed the datasource name from com.mysql.cj.jdbc.MysqlDataSource to com.mysql.cj.jdbc.Driver in the Glassfish Domain Admin Console and I got a new error. "Ping Connection Pool failed for OkStorePool. Class name is wrong or classpath is not set for : com.mysql.cj.jdbc.Driver." So I swap backed to com.mysql.cj.jdbc.MysqlDataSource. The datasource name change error

  • 1
    It looks like that error is due to your use of the old driver mysql-connector-java-5.1.47 with MySQL 8.x. See [(CDAP-17379) connection string not correctly constructed for mysql if mysql driver 5 is used](https://groups.google.com/g/cdap-issues/c/y6ppSOX2KhM). The solution is to replace that old driver with the latest one for MySQL 8.x. [Download it from here.](https://dev.mysql.com/downloads/connector/j/). Note that you don't explicitly download the driver file. Instead you download/install/run the MySQL Installer, then request that it installs the driver on your behalf. – skomisa Dec 22 '22 at 22:37
  • ....(n.b. If you have previously downloaded/installed the _MySQL Installer_ then just run it, then select **MySQL Connectors > Connector/J > Connector/J 8.0** from the list of _Available Products_.) – skomisa Dec 22 '22 at 22:44
  • Alright I have deleted the old driver and downloaded the new one but I still have the same error message. thanks for trying – Makito Bredy Dec 23 '22 at 00:38
  • I changed the datasource name in the Glassfish Domain Admin Console and I got a new error. "Ping Connection Pool failed for OkStorePool. Class name is wrong or classpath is not set for : com.mysql.cj.jdbc.Driver." – Makito Bredy Dec 23 '22 at 20:57

1 Answers1

0

Guys I fixed the problem. I went to the glassfish-resources.xml file and changed jdbc:mysql://localhost:3306/okstore?zeroDateTimeBehavior=CONVERT_TO_NULL to jdbc:mysql://localhost:3306/okstore?zeroDateTimeBehavior=convertToNull. I also changed the database connection to jdbc:mysql://localhost:3306/okstore?zeroDateTimeBehavior=convertToNull just in case.