既存の Java EE ベースのアプリケーションに取り組んでいます。これは、データベースに接続するための次の方法を備えています。
public static java.sql.Connection connectionToDataBase(String jndiName,boolean flag)throws Exception
{
DataSource ds =(javax.sql.DataSource) initCtx.lookup(jndiName);
return ds.getConnection();
} catch (NamingException ne) {
throw ne;
} finally {
try {
if (initCtx != null)
initCtx.close();
} catch (NamingException ne) {
throw ne;
}
}
}
私の質問は、データベースへの接続に静的メソッドを使用することが正しいかどうかです。