Communications link failure due to underlying exception
hello
I try to connect to the database
Exception
Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: java.net.ConnectException: Connection refused STACKTRACE: java.net.SocketException:
local on my home pc works fine but by my hoster works not
whaht shoud be the problem ?
public DataSource setupDataSource()
{
PoolingDataSource dataSource =null;
try{
Class.forName(driverName);
ObjectPool connectionPool =new GenericObjectPool(null);
ConnectionFactory connectionFactory =new DriverManagerConnectionFactory(Url,DBUser,DBPwd);
PoolableConnectionFactory poolableConnectionFactory =new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
dataSource =new PoolingDataSource(connectionPool);
}catch(Exception ex){
ex.printStackTrace();
}
return dataSource;
}
//
public Vector getLinks(String type)
{
Vector retObj =new Vector();
DataSource dataSource = setupDataSource();
Connection con =null;
Statement stmt =null;
try
{
con = dataSource.getConnection();
stmt = con.createStatement();
ResultSet rset = stmt.executeQuery(queryCreator.getLinksQuery(type));
while(rset !=null && rset.next()){
LinkObject linkObject =new LinkObject();
linkObject.setCaptionkey(rset.getString("CaptionKey"));
linkObject.setImage(rset.getBoolean("IsImage"));
linkObject.setAltkey(rset.getString("AltKey"));
if( type.equalsIgnoreCase(AppConstants.HEADLINKS)){
linkObject.setUrl(rset.getString("Url"));
}
retObj.addElement(linkObject);
}
}catch(SQLException sqlEx){
sObjs.addErrorMessage("[SQLFactory ->Exception: -> ["+type+" -> getLinks()]"+sqlEx.getMessage());
}finally{
checkClosedConnections(con,stmt,"getLinks()");
}
return retObj;
}
//--
publicvoid checkClosedConnections(Connection con, Statement stmt,String method)
{
if (stmt !=null){
try{
stmt.close();
}catch (SQLException sqlEx){
sObjs.addErrorMessage("[SQLFactory ->Exception: -> checkClosedConnections()-> "+ method +"]"+sqlEx.getMessage());
}
stmt =null;
}
if (con !=null){
try{
con.close();
}catch (SQLException sqlEx){
sObjs.addErrorMessage("[SQLFactory ->Exception: -> checkClosedConnections()-> "+ method +"]"+sqlEx.getMessage());
}
con =null;
}
}
// -

