Blacol 2022-02-22 12:38 采纳率: 100%
浏览 516
已结题

SpringBoot+嵌入式h2 插入数据时报错,提示table not found

日志

### The error may exist in com/blacol/ncd/mapper/BaseInfoMapper.java (best guess)
### The error may involve com.blacol.ncd.mapper.BaseInfoMapper.insert
### The error occurred while executing an update
### SQL: INSERT INTO PUBLIC.BASEINFO  ( id, name, foreignName, gender, height, weight, country, age, nation, education, bmi, iq, eq, energy, worldView, createTime )  VALUES  ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
### Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "BASEINFO" not found; SQL statement:
INSERT INTO PUBLIC.BASEINFO  ( id,
name,
foreignName,
gender,
height,
weight,
country,
age,
nation,
education,
bmi,
iq,
eq,
energy,
worldView,
createTime )  VALUES  ( ?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
? ) [42102-200]

表结构

create table BASEINFO
(
    ID          CHARACTER not null,
    NAME        CHARACTER,
    FOREIGNNAME CHARACTER,
    HEIGHT      DOUBLE PRECISION,
    WEIGHT      DOUBLE PRECISION,
    COUNTRY     CHARACTER,
    AGE         INTEGER,
    NATION      CHARACTER,
    EDUCATION   CHARACTER,
    BMI         DOUBLE PRECISION,
    IQ          INTEGER,
    EQ          INTEGER,
    ENERGY      INTEGER,
    WORLDVIEW   CHARACTER,
    CREATETIME  DATE,
    GENDER      CHARACTER(1),
    constraint BASEINFO_PK
        primary key (ID)
);

Spring Boot配置文件

spring.datasource.url=jdbc:h2:~/db/ncd.mv.db;DB_CLOSE_DELAY=-1 # 有无DB_CLOSE_DELAY配置都一样
spring.web.resources.static-locations=classpath:/static/

实体类

package com.blacol.ncd.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import java.sql.Date;
@TableName("PUBLIC.BASEINFO")
//改成BASEINFO、baseinfo、public.baseinfo、@TableName(schema="PUBLIC",value="BASEINFO")均无效
public class BaseInfo {
    private String id;
    private String name;
    @TableField("foreignName")
    private String foreignName;
    private String gender;
    private double height;
    private double weight;
    private String country;
    private int age;
    private String nation;
    private String education;
    private double bmi;
    private int iq;
    private int eq;
    private int energy;
    @TableField("worldView")
    private String worldView;
    @TableField("createTime")
    private Date createTime;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getForeignName() {
        return foreignName;
    }

    public void setForeignName(String foreignName) {
        this.foreignName = foreignName;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getNation() {
        return nation;
    }

    public void setNation(String nation) {
        this.nation = nation;
    }

    public String getEducation() {
        return education;
    }

    public void setEducation(String education) {
        this.education = education;
    }

    public double getBmi() {
        return bmi;
    }

    public void setBmi(double bmi) {
        this.bmi = bmi;
    }

    public int getIq() {
        return iq;
    }

    public void setIq(int iq) {
        this.iq = iq;
    }

    public int getEq() {
        return eq;
    }

    public void setEq(int eq) {
        this.eq = eq;
    }

    public int getEnergy() {
        return energy;
    }

    public void setEnergy(int energy) {
        this.energy = energy;
    }

    public String getWorldView() {
        return worldView;
    }

    public void setWorldView(String worldView) {
        this.worldView = worldView;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    @Override
    public String toString() {
        return "BaseInfo{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", foreignName='" + foreignName + '\'' +
                ", gender='" + gender + '\'' +
                ", height=" + height +
                ", weight=" + weight +
                ", country='" + country + '\'' +
                ", age=" + age +
                ", nation='" + nation + '\'' +
                ", education='" + education + '\'' +
                ", bmi=" + bmi +
                ", iq=" + iq +
                ", eq=" + eq +
                ", energy=" + energy +
                ", worldView='" + worldView + '\'' +
                ", createTime=" + createTime +
                '}';
    }
}

插入的数据

通过Mybatis-plus插入,插入实体类BaseInfo的对象,为了更直观的展示数据使用JSON表示:

{
    "age":26,
    "bmi":23.62,
    "country":"sd",
    "createTime":1645504184362,
    "education":"bbbb",
    "energy":6,
    "eq":6,
    "foreignName":"sda",
    "gender":"m",
    "height":177,
    "id":"cc067f728381496",
    "iq":6,
    "name":"adas",
    "nation":"dd",
    "weight":74,
    "worldView":"ggg"
}
  • 写回答

2条回答 默认 最新

  • Blacol 2022-02-25 10:57
    关注

    已解决:
    主要是因为idea项目结构的问题。
    SpringBoot项目打包后会生成 target文件夹, h2的数据库文件也打包了进去。这样程序运行时是访问target里的数据库。如果要访问项目中的数据库文件可以将配置中url的~改成.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 2月25日
  • 已采纳回答 2月25日
  • 创建了问题 2月22日

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表