我不断收到错误消息,指出try
(public Connection getConnection()
内部)需要catch
子句。我不明白为什么编译器没有直接注意try
下的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);
}
}
}
。有谁知道为什么它不会编译?我也检查了所有括号......
{{1}}