// 图片保存模块 public void saveImage(Image image) { // 将图片信息保存到数据库 try { Connection conn = DriverManager.getConnection('jdbc:mysql://localhost:3306/image_db', 'root', 'password'); // 建立数据库连接 PreparedStatement ps = conn.prepareStatement('INSERT INTO images (name, path) VALUES (?, ?)'); // 创建预处理语句 ps.setString(1, image.getName()); // 设置参数 ps.setString(2, image.getPath()); ps.executeUpdate(); // 执行更新操作 ps.close(); // 关闭预处理语句 conn.close(); // 关闭数据库连接 } catch (SQLException e) { e.printStackTrace(); } }

// 图片浏览模块 public void browseImages() { // 从数据库中读取图片信息,显示到界面上 try { Connection conn = DriverManager.getConnection('jdbc:mysql://localhost:3306/image_db', 'root', 'password'); // 建立数据库连接 Statement stmt = conn.createStatement(); // 创建语句对象 ResultSet rs = stmt.executeQuery('SELECT * FROM images'); // 执行查询操作 while (rs.next()) { // 遍历结果集 Image image = new Image(rs.getString('name'), rs.getString('path')); // 将图片显示到界面上 } rs.close(); // 关闭结果集 stmt.close(); // 关闭语句对象 conn.close(); // 关闭数据库连接 } catch (SQLException e) { e.printStackTrace(); }

// 单击某一张图片,弹出菜单,显示相关操作
// 代码省略

}

// 图片编辑模块 public void editImage(Image image) { // 根据用户选择的操作,对图片进行编辑 // 包括旋转、边界检测、图像锐化、对比度增强、图像风格化等操作 // 代码省略 }

// 图片删除模块 public void deleteImage(Image image) { // 从数据库中删除该图片信息 try { Connection conn = DriverManager.getConnection('jdbc:mysql://localhost:3306/image_db', 'root', 'password'); // 建立数据库连接 PreparedStatement ps = conn.prepareStatement('DELETE FROM images WHERE name = ?'); // 创建预处理语句 ps.setString(1, image.getName()); // 设置参数 ps.executeUpdate(); // 执行更新操作 ps.close(); // 关闭预处理语句 conn.close(); // 关闭数据库连接 } catch (SQLException e) { e.printStackTrace(); } }

// 图片检索模块 public void searchImages(String keyword) { // 根据关键词在数据库中检索图片信息 // 显示检索结果 try { Connection conn = DriverManager.getConnection('jdbc:mysql://localhost:3306/image_db', 'root', 'password'); // 建立数据库连接 PreparedStatement ps = conn.prepareStatement('SELECT * FROM images WHERE name LIKE ?'); // 创建预处理语句 ps.setString(1, '%' + keyword + '%'); // 设置参数 ResultSet rs = ps.executeQuery(); // 执行查询操作 while (rs.next()) { // 遍历结果集 Image image = new Image(rs.getString('name'), rs.getString('path')); // 将检索结果显示到界面上 } rs.close(); // 关闭结果集 ps.close(); // 关闭预处理语句 conn.close(); // 关闭数据库连接 } catch (SQLException e) { e.printStackTrace(); } }

Java 图片管理系统:保存、浏览、编辑、删除、检索

原文地址: https://www.cveoy.top/t/topic/f1qZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录