I'm working with java and databases. I have a connections class PgConnection and within this class I have a private connection variable
private Connection Con = null;
Within the constructor the Connection is created
Properties props = new Properties();
props.load(Thread.currentThread().getContextClassLoader()
.getResourceAsStream("database.properties"));
String url = props.getProperty("db.url");
String user = props.getProperty("db.user");
String passwd = props.getProperty("db.passwd");
Class.forName("org.postgresql.Driver");
this.con = DriverManager.getConnection(url, user, passwd);
When looking to use this con
variable throughout my code I have been referencing it by assigning it to a local variable within a function Connection conn = this.con;
Is this correct practice? And if so, should I be closing conn
before exiting the function. Once I am finished with a particular instance of PgConnection I have a Close() method that closes this.con
Thanks