Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-1035

PreparedStatement Insert regression - java.sql.SQLSyntaxErrorException: (conn=952) Incorrect datetime value: '2022-12-16 16:21:25.7134102022-12-16 16:21:25.713410'

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 3.1.0
    • 3.1.1
    • Other
    • Ubuntu 20.04, Mariadb 10.6.11, Java 17

    Description

      Use PreparedStatement to insert 152 tuples of values of 3 elements with contains a LocalDateTime element. Mariadb returns a SQLSyntaxErrorException. The same code works for version 3.0.8.

      However, the insert statement will work for values right up to 151 tuples.

      Here is the preparestatement string generated from the Scala code listed below.

      INSERT INTO Test (`name`, `description`, `created`) VALUES (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?, ?, ?)

      Sample code are written in Scala 3.

      ```
      /*
      CREATE TABLE `Test` (
      `name` varchar(255) NOT NULL,
      `description` varchar(255) DEFAULT NULL,
      `created` datetime DEFAULT Now(),
      PRIMARY KEY (`name`)
      );
      */

      val count = 151
      val insert = """INSERT INTO Test (`name`, `description`, `created`) VALUES """
      val params = "(?,?,?), ".repeat(count) + "(?, ?, ?)"
      val indexPlaceholderStatement = insert + params //See above for the actual statement string
      val preparedStatement = connection.prepareStatement(indexPlaceholderStatement, java.sql.Statement.RETURN_GENERATED_KEYS)
      val now: Any = java.time.LocalDateTime.now
      0 to count foreach { i =>
      val offset = i * 3
      preparedStatement.setString(offset + 1, s"name ${i}")
      preparedStatement.setString(offset + 2, s"desc ${i} ")
      preparedStatement.setObject(offset + 3, now)
      }
      preparedStatement.executeUpdate()
      connection.commit()
      ```

      Attachments

        Issue Links

          Activity

            diego dupin Diego Dupin added a comment -

            thanks for the reproductible case, it helps a lot !
            It's corrected with https://github.com/mariadb-corporation/mariadb-connector-j/commit/7399a26026b5562296fe1a104793a7ad8de6905a

            correction is available using snapshot :

            <repositories>
                <repository>
                    <id>sonatype-nexus-snapshots</id>
                    <name>Sonatype Nexus Snapshots</name>
                    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
                </repository>
            </repositories>
             
            <dependencies>
                <dependency>
                    <groupId>org.mariadb.jdbc</groupId>
                    <artifactId>mariadb-java-client</artifactId>
                    <version>3.1.1-SNAPSHOT</version>
                </dependency>
            </dependencies>
            

            diego dupin Diego Dupin added a comment - thanks for the reproductible case, it helps a lot ! It's corrected with https://github.com/mariadb-corporation/mariadb-connector-j/commit/7399a26026b5562296fe1a104793a7ad8de6905a correction is available using snapshot : <repositories> <repository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus Snapshots</name> <url>https: //oss.sonatype.org/content/repositories/snapshots</url> </repository> </repositories>   <dependencies> <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> <version> 3.1 . 1 -SNAPSHOT</version> </dependency> </dependencies>

            I am glad you have help solved it. BTW, we had the same problem for java.time.LocalTime as well. I hope it is the same category of problem.

            Again, many thanks resolving the bug

            chungonn Cheong Chung Onn added a comment - I am glad you have help solved it. BTW, we had the same problem for java.time.LocalTime as well. I hope it is the same category of problem. Again, many thanks resolving the bug

            Hi Diego, I just tested using the snapshot and push it to 1500 tuples and it works! Thanks for the speed fix.

            chungonn Cheong Chung Onn added a comment - Hi Diego, I just tested using the snapshot and push it to 1500 tuples and it works! Thanks for the speed fix.
            diego dupin Diego Dupin added a comment -

            about LocalTime, yes, that is the same kind of problem

            diego dupin Diego Dupin added a comment - about LocalTime, yes, that is the same kind of problem

            Noted with thanks!

            chungonn Cheong Chung Onn added a comment - Noted with thanks!

            People

              diego dupin Diego Dupin
              chungonn Cheong Chung Onn
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.