In spring boot (2.7.8-SNAPSHOT) environment, I changed my DB from H2DB to My SQL (mysql-connector-j-8.0.32), but I got an error.

Asked 1 years ago, Updated 1 years ago, 402 views

In the H2 environment, type conversion was possible, but when I switched to My SQL, I got an error.
I didn't know exactly where and how to fix it.
I would appreciate it if you could help me.

·The following environment

plugins{
    id'java'
    id'org.springframework.boot'version'2.7.8 - SNAPSHOT'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group='com.example'
version = '0.0.1 - SNAPSHOT'
sourceCompatibility='11'

repositories {
    mavenCentral()
    maven {url'https://repo.spring.io/milestone'}
    maven {url'https://repo.spring.io/snapshot'}
}

dependencies {
    implementation'org.springframework.boot:spring-boot-starter-jdbc'
    implementation'org.springframework.boot:spring-boot-starter-security'
    implementation'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation'org.springframework.boot:spring-boot-starter-validation'
    implementation'org.springframework.boot:spring-boot-starter-web'
    implementation'org.tymeleaf.extras:tymeleaf-extras-springsecurity5'
    developmentOnly'org.springframework.boot:spring-boot-devtools'
    runtimeOnly'com.h2database:h2'
    runtimeOnly'com.mysql:mysql-connector-j'
        testImplementation('org.springframework.boot:spring-boot-starter-test'){
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation'org.springframework.security:spring-security-test'
    testRuntimeOnly'org.junit.platform:junit-platform-launcher'
    testImplementation('org.mockito:mockito-core:3.6.0')
    testImplementation('org.mockito:mockito-junit-jupiter:3.6.0')
}

tasks.named ('test') {
    useJUnitPlatform()
}

·DaoImpl file with error below

task.setDeadline((Timestamp) result.get("deadline")).toLocalDateTime());

·The following error contents

java.lang.ClassCastException: class java.time.LocalDateTime cannot be
cast to class java.sql.Timestamp(java.time.LocalDateTime is in module
) java.base of loader 'bootstrap'; java.sql.Timestamp is in module
java.sql of loader 'platform')

·Executed SQL

CREATE TABLE task
(
    id INT NOT NULL AUTO_INCREMENT,
    user_id INT NOT NULL,
    type_id INT NOT NULL,
    title VARCHAR(50) NOT NULL,
    detail TEXT,
    deadline DATETIME NOT NULL,
    PRIMARY KEY (id)
);

java mysql

2023-02-09 08:20

1 Answers

We were able to deal with the following corrections.

task.setDeadline(LocalDateTime)result.get("deadline"));


2023-02-09 09:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.