Currently my program establishes a connection to the server each time it needs to and closes the connection after it grabs what it needs.
Connection con = DriverManager.getConnection(url, user, pass);
//grab data
con.close();
Is it better or worse practice and what difference would it make if I just had one global connection running from the start of the program. Something like
public static Connection con = DriverManager.getConnection(url, user, pass);
And just referenced it wherever I needed it with something like
classname.con.createStatement();
This depends on your application. You should code like what you need -- however one session for a big application can introduce problems.
For example thread safety. If multiple users are connected to your application one session / connection is out of the scope.
I would use one connection per request -- with an additional connection pool and maximum amount of open connections.
And because using a connection can throw exceptions put your code inside a
try-with-resources
block and then your connection is closed automatically.