使用Oracle JDBC Java API插入Oracle DB时的Springboot错误

发布于 2025-02-13 23:09:45 字数 1342 浏览 0 评论 0原文

我得到了错误引起的:错误:932,位置:70,SQL =插入t_table1(create_time,log,id)value log,id)值(?,?,?),错误msg = ora-00932:不一致的datatypes:预期时间戳获得二进制

没有其他文章解决我的问题

主要:

DATE th = new DATE(); //oracle.sql.DATE
LogService.saveLoggingData(new LogEntity("test log",th));

logentity:

import oracle.sql.DATE;
import javax.persistence.*;

@Entity
@Table(name = "T_table1")
public class LogEntity{
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "ID")
    private long id;

    @Column(name = "LOG")
    private String log;

    @Column(name = "CREATED_TIME")
    private DATE ts;

    public LogEntity(){

    }
    public LogEntity(String logEvent, DATE createdAt){
        this.ts = createdAt;
        this.logEvent = logEvent;
    }

}

logService:

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    LogRepository LogRepository;

    @Override
    public void saveLoggingData(LogEntity log) {
        LogRepository.save(log);
    }
}

logrepository:

@Repository
public interface LogRepository extends JpaRepository<LogEntity, Long>{

}

oracle表范围create_time_time是类型timestamp(6)。但是我显然是在主要插入非编码> date 的主要内容,为什么它变成二进制?

I got the error Caused by: Error : 932, Position : 70, Sql = insert into T_table1 (CREATED_TIME, LOG, ID) values (:1 , :2 , :3 ), OriginalSql = insert into T_table1 (CREATED_TIME, LOG, ID) values (?, ?, ?), Error Msg = ORA-00932: inconsistent datatypes: expected TIMESTAMP got BINARY.

None of the other posts solved my problem

Main:

DATE th = new DATE(); //oracle.sql.DATE
LogService.saveLoggingData(new LogEntity("test log",th));

LogEntity:

import oracle.sql.DATE;
import javax.persistence.*;

@Entity
@Table(name = "T_table1")
public class LogEntity{
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "ID")
    private long id;

    @Column(name = "LOG")
    private String log;

    @Column(name = "CREATED_TIME")
    private DATE ts;

    public LogEntity(){

    }
    public LogEntity(String logEvent, DATE createdAt){
        this.ts = createdAt;
        this.logEvent = logEvent;
    }

}

LogService:

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    LogRepository LogRepository;

    @Override
    public void saveLoggingData(LogEntity log) {
        LogRepository.save(log);
    }
}

LogRepository:

@Repository
public interface LogRepository extends JpaRepository<LogEntity, Long>{

}

Oracle Table field CREATED_TIME is of type TIMESTAMP (6). But I am clearly inserting a nonnull DATE in the main, why did it become binary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此刻的回忆 2025-02-20 23:09:45

我认为您首先有两个问题

,logentity构造函数正在为参数本身设置值。

public LogEntity(String logEvent, DATE createdAt){
    this.ts = createdAt;
    this.logEvent = logEvent;
}

必须是:

public LogEntity(String logEvent, DATE createdAt){
    this.ts = createdAt;
    this.log = logEvent;
}

另一方面,我认为使用Oracle日期不适合此插入物。您应该使用Java Util库中的日期

Replace oracle.sql.DATE for java.util.Date;

I think you have two problems

First, the LogEntity constructor is setting the value to the argument itself.

public LogEntity(String logEvent, DATE createdAt){
    this.ts = createdAt;
    this.logEvent = logEvent;
}

Its must be:

public LogEntity(String logEvent, DATE createdAt){
    this.ts = createdAt;
    this.log = logEvent;
}

On the other hand, I think that using the Oracle Date is not suitable for this insert. You should use the Date from the Java Util library

Replace oracle.sql.DATE for java.util.Date;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文