我有两个连接到数据库的客户端,一旦其中一个执行了插入查询,例如另一个下面的一个,则永远无法执行任何插入查询,但仍可以执行选择查询。任何想法如何两个客户可以插入?
public int insertShiftHandover(String handoverDate, String unit, String shift, String handover) {
String sql = "INSERT INTO ShiftHandover(unit,date,timePeriod,information) VALUES(?,?,?,?)";
PreparedStatement pstmt = null;
int success = 0;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, unit);
pstmt.setString(2, handoverDate);
pstmt.setString(3, shift);
pstmt.setString(4, handover);
pstmt.executeUpdate();
success = 1;
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
pstmt.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
return success;
}