TIMESTAMP フィールドに正しく挿入できません。
メソッドは次のようになります。
private static void addPickup(Connection conn, boolean debug, String
logfileName, String serverName, String mapName, long start,
long end) throws SQLException {
try (CallableStatement statement = conn.prepareCall("{CALL AddPickup "
+ "(?, ?, ?, ?, ?) }")) {
statement.setString(1, logfileName);
statement.setString(2, serverName);
statement.setString(3, mapName);
statement.setTimestamp(4, new Timestamp(start));
statement.setTimestamp(5, new Timestamp(end));
statement.execute();
}
}
start の値は 1373573918000 です
end の値は 1373574819000 です
手順:
CREATE PROCEDURE AddPickup(
IN logfilename VARCHAR(45),
IN servername VARCHAR(10),
IN mapname VARCHAR(20),
IN start TIMESTAMP,
IN end TIMESTAMP
)
AddPickup:BEGIN
IF EXISTS(SELECT p.id FROM pickup p WHERE p.logfile_name = logfilename) THEN
LEAVE AddPickup;
END IF;
INSERT IGNORE INTO map (name) VALUES (mapname);
INSERT IGNORE INTO server (name) VALUES (servername);
INSERT INTO pickup (logfile_name, server_id, map_id, started, ended, datetime)
VALUES (
logfilename,
(SELECT s.id FROM server s WHERE s.name = servername),
(SELECT m.id FROM map m WHERE m.name = mapname),
start,
end,
NOW()
);
END //
テーブル:
CREATE TABLE map (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(20) UNIQUE NOT NULL
) ENGINE = 'InnoDB';
CREATE TABLE server (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(10) UNIQUE NOT NULL
) ENGINE = 'InnoDB';
CREATE TABLE pickup (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
logfile_name VARCHAR(45) UNIQUE NOT NULL,
server_id INT UNSIGNED NOT NULL,
map_id INT UNSIGNED NOT NULL,
started TIMESTAMP NOT NULL,
ended TIMESTAMP NOT NULL,
datetime DATETIME NOT NULL,
FOREIGN KEY (map_id) REFERENCES map(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (server_id) REFERENCES server(id) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE = 'InnoDB';
TIMESTAMPフィールドのpickup.startedと pickup.endedの両方に常に「0000-00-00 00:00:00」が表示され、その理由がわかりません。