I keep getting an error stating I need a catch
clause to accompany the try
(inside public Connection getConnection()
). I dont understand why the compiler isn't noticing the catch
directly under the try
. Does anyone know why it won't compile? I checked all my brackets as well...
package crud.data;
import java.sql.*;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ConnectionPool
{
private static ConnectionPool pool = null;
private static DataSource dataSource = null;
private ConnectionPool()
{
try
{
InitialContext ic = new InitialContext();
dataSource = (DataSource)
ic.lookup("java:/comp/env/jdbc/acm14n");
}
catch (NamingException e)
{
System.out.println(e);
}
}
public static synchronized ConnectionPool getInstance()
{
if(pool == null)
{
pool = new ConnectionPool();
}
return pool;
}
public Connection getConnection()
{
try
{
return dataSource.getConnection();
}
catch (SQLException e)
{
System.out.println(e);
return null;
}
}
public void freeConnection(Connection c)
{
try
{
c.close();
}
catch (SQLException e)
{
System.out.println(e);
}
}
}