Reputation: 11
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;
}
I am getting following exception :
com.microsoft.sqlserver.jdbc.SQLServerException: Operand type clash: int is incompatible with datetime2
Upvotes: 1
Views: 70
Reputation: 2287
Instead of this
pst.setInt(7, td.getScore());
use
pst.setInt(8, td.getScore());
7th
argument is already there as CURRENT_TIMESTAMP
.you are insterested to set 8th
one.
UPDATE
try this
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;
}
}
Upvotes: 2
Reputation: 135
May be the variable score is of datetime type thats why it is giving this exception, just try to use setTime() of Calender class instead of the setInt().
Upvotes: 0