Hi,
I have created the following code to get connection object to Database(MySql in my case) using a static method. I wanna know whether it is a good practice or not? Will there be any problem like concurrent access?
Any information will be helpful.
public static Connection connection(){
Connection conn = null;
String userName = "abcd";
String password = "abcd";
String url = "jdbc:mysql://localhost/abcd";
String driver="com.mysql.jdbc.Driver";
try{
Class.forName (driver);
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch(Exception e){
e.printStackTrace();
}
return conn;
}