import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class ConnectionManager {
private final static String JNDI_Name = "java:comp/env/jdbc/sso";
private static javax.sql.DataSource dataSource = null;
public static Connection getConnection()
{
if (dataSource==null)
{
synchronized(ConnectionManager.class)
{
if (dataSource==null)
{
Context initCtx = null;
try
{
String jndiName = System.getProperty("sso.jndiName");
if (jndiName==null || "".equals(jndiName))
jndiName=JNDI_Name;
initCtx = new InitialContext();
dataSource = (DataSource) initCtx.lookup(jndiName);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
try
{
if (dataSource!=null)
return dataSource.getConnection();
else
{
System.out.println("dataSource is null");
}
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
}