如何在Java中将图像路径保存到sql数据库 [英] how to save image path to sql database in java

查看:271
本文介绍了如何在Java中将图像路径保存到sql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将jfilechooser选择的映像路径保存到sql数据库,并每次从该sql路径加载该映像.我正在使用prepareStatment.但是我将路径保存在sql数据库中,没有"\".这是我的代码的一部分.请对此提供帮助.

I have to save the image path chosen by jfilechooser to sql database and load that image every time from that sql path. Im using preparedStatment . But I got the path saved in sql database without "\" . Here is part my code.. Please help me on this.

    PreparedStatement ps = null;
    ResultSet rs = null;
    Connection conn = null;
conn = DBConnection.ConnectDB();

 try {
            JFileChooser choose = new JFileChooser();
            choose.showOpenDialog(null);
            File f = choose.getSelectedFile();
            if (f != null) {
                fileName = f.getAbsolutePath();

                String sql = "UPDATE addskin SET Path='" + fileName + "' WHERE Name='Assigned'";
                ps = conn.prepareStatement(sql);
                ps.execute();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

推荐答案

标准解决方案是快速解决方案是用一些特殊字符替换斜杠,然后稍后再将其更改.

Quick solution is replace slash with some special character, while change it back later.

这篇关于如何在Java中将图像路径保存到sql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆