使用Oracle JDBC Java API插入Oracle DB时的Springboot错误
我得到了错误引起的:错误: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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您首先有两个问题
,logentity构造函数正在为参数本身设置值。
必须是:
另一方面,我认为使用Oracle日期不适合此插入物。您应该使用Java Util库中的日期
I think you have two problems
First, the LogEntity constructor is setting the value to the argument itself.
Its must be:
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