【发布时间】:2015-03-31 07:24:31
【问题描述】:
我在一个只有两列的表中有大约 160 万行,一个是 bigint 唯一索引,另一个是 longblob,在 base64 中有照片。我需要尽快解码这些 base64 照片。我尝试使用几个小时后中断的java程序,速度也不好。这是程序
Connection conn = null;
Statement stmt = null;
try {
conn = DatabaseConnection.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = stmt.executeQuery("SELECT uniqueid,photo FROM newphotodata");
String query="insert into photo_data values (?,?)";
PreparedStatement pstmt = conn.prepareStatement(query);
while (uprs.next()) {
byte[] processed = Base64Utils.base64Decode(uprs.getString(2));
pstmt.setString(1, uprs.getString(1));
pstmt.setBytes(2, processed);
pstmt.executeUpdate();
uprs.deleteRow();
}
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (stmt != null)
stmt.close();
if(conn!=null)
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
我采用的第二种方法是使用数据库触发器,它使用我创建的 base64_decode 存储过程。这是触发器
DELIMITER $$
DROP TRIGGER `delete_photo`$$
CREATE TRIGGER `delete_photo` BEFORE DELETE ON `newphotodata`
FOR EACH ROW
BEGIN
INSERT INTO `photo_data` SELECT OLD.`uniqueid`, BASE64_DECODE(OLD.`photo`);
END$$
DELIMITER ;
处理速度又太慢了。是否有任何其他方法可用于执行以下任务。我在 Redhat Linux 上运行 Mysql 5.0 版,96GB RAM,intel Xeon x5672。
【问题讨论】:
标签: java mysql sql linux stored-procedures