PeakGen
PeakGen

Reputation: 23025

Where should I save the JDBC connectivity details?

I have a Java Swing program with database connnection. 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.

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. So I am planning to create a small dialog box for the client to enter the DB Password, user, and server location. 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?

Upvotes: 2

Views: 566

Answers (1)

trashgod
trashgod

Reputation: 205785

You can store the connection details using java.util.prefs.Preferences, as suggested here, or a javax.jnlp.PersistenceService, as suggested here. Although platforms typically protect such data from casual snooping, you can store a salted hash using one of the approaches shown here.

Upvotes: 3

Related Questions