简体   繁体   English

我应该在哪里保存JDBC连接详细信息?

[英]Where should I save the JDBC connectivity details?

I have a Java Swing program with database connnection. 我有一个与数据库连接的Java Swing程序。 Up to now, my requirement was to hard code the connection details like below. 到目前为止,我的要求是对连接细节进行如下硬编码。

public void makeConnection() 
    {
        try
        {
             Class.forName("com.mysql.jdbc.Driver");

             con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbName","root","");

             //System.out.println("Connection Established");
        }
        catch(Exception e)
        {
            e.printStackTrace();

        }
    }

However the client's IT guy tried to make the connection to the DB via a VPN, and the system rejected to connect, most probably because the hard coded connectivity. 但是,客户的IT人员试图通过VPN与数据库建立连接,而系统拒绝连接,这很可能是因为硬编码连接。

Now, I am looking for ways to store the connectivity data in a way that client can edit. 现在,我正在寻找以客户端可以编辑的方式存储连接数据的方法。 Which means, like most general programs, client decides the db password, port etc. He might need it bcs a VPN is involved. 这意味着,与大多数常规程序一样,客户端决定db密码,端口等。他可能需要使用bcs,因为涉及VPN。 So I am planning to create a small dialog box for the client to enter the DB Password, user, and server location. 因此,我计划为客户端创建一个小对话框,以输入DB密码,用户和服务器位置。 Once these data are saved, the program will read them and make the connection accordingly. 保存这些数据后,程序将读取它们并进行相应的连接。

But the problem is, where do I save these? 但是问题是,我该将它们保存在哪里? I know I can save them in a Text file but it is a non-secured method, any one can read it. 我知道我可以将它们保存在文本文件中,但这是一种不安全的方法,任何人都可以读取它。 some kind of hard coding is not an option, because client should be able to edit his password etc etc. 某种形式的硬编码不是一种选择,因为客户端应该能够编辑他的密码等。

Any advice? 有什么建议吗?

You can store the connection details using java.util.prefs.Preferences , as suggested here , or a javax.jnlp.PersistenceService , as suggested here . 您可以使用存储连接的细节java.util.prefs.Preferences ,如建议在这里 ,或javax.jnlp.PersistenceService ,作为建议在这里 Although platforms typically protect such data from casual snooping, you can store a salted hash using one of the approaches shown here . 尽管平台通常会保护此类数据免受偶然的窥探,但是您可以使用此处显示的方法之一存储加盐的哈希。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM