Skip to content

Instantly share code, notes, and snippets.

@anupsavvy
Last active December 14, 2015 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anupsavvy/4998535 to your computer and use it in GitHub Desktop.
Save anupsavvy/4998535 to your computer and use it in GitHub Desktop.
Singleton Class
public class DataSource {
private Connection connection = null;
private static DataSource datasource = null;
// private constructor
private DataSource(){
connection = getConnection();
}
// method to get an instance.
public static DataSource getInstance(){
if(datasource == null){
datasource = new DataSource();
}
return datasource;
}
private Connection getConnection(){
// code to get database connection.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment