gpt4 book ai didi

java - 微软sql错误异常

转载 作者:行者123 更新时间:2023-11-30 03:09:56 26 4
gpt4 key购买 nike

 try {
// con = dbConn.mySqlConnection();
con = DatabaseConnection.getRAWConnection();
String insertSqlTable = "insert into certification VALUES(?,?,?,?,?,?,CURRENT_TIMESTAMP,?)";
pst = con.prepareStatement(insertSqlTable);
pst.setInt(1, td.getEmpId());
pst.setString(2, td.getRname());
pst.setString(3, td.getStream());
pst.setString(4, td.getCertificationType());
pst.setString(5, td.getCertificationName());
pst.setString(6, td.getCertificationDate());
//pst.setTimestamp(7, timestamp);
pst.setInt(7, td.getScore());

int count = pst.executeUpdate();
if (count >= 1) {
con.commit();
status = true;
} else {
System.out.println("Error occured while inserting certification details into database");
con.rollback();
status = false;
}

我遇到以下异常:

com.microsoft.sqlserver.jdbc.SQLServerException: Operand type clash: int is incompatible with datetime2

最佳答案

而不是这个

pst.setInt(7, td.getScore());

使用

pst.setInt(8, td.getScore());

第 7 参数已作为 CURRENT_TIMESTAMP 存在。您有兴趣将第 8 参数设置为 1。

更新

试试这个

try {
// con = dbConn.mySqlConnection();
con = DatabaseConnection.getRAWConnection();
String insertSqlTable = "insert into certification VALUES(?,?,?,?,?,?,?,?)";
pst = con.prepareStatement(insertSqlTable);
pst.setInt(1, td.getEmpId());
pst.setString(2, td.getRname());
pst.setString(3, td.getStream());
pst.setString(4, td.getCertificationType());
pst.setString(5, td.getCertificationName());
pst.setString(6, td.getCertificationDate());
java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime());
pst.setTimestamp(7, date);
pst.setInt(8, td.getScore());

int count = pst.executeUpdate();
if (count >= 1) {
con.commit();
status = true;
} else {
System.out.println("Error occured while inserting certification details into database");
con.rollback();
status = false;
}

}

关于java - 微软sql错误异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33818813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com