错误java:38:错误:'尝试'没有'赶上'最后'或资源声明

时间:2018-04-10 02:24:10

标签: java connection-pooling connection-pool

我不断收到错误消息,指出trypublic 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}}

0 个答案:

没有答案