public static Connection getConnection1() throws ServletException {
Connection con = null;
try {
Context initCtx = new InitialContext();
//tomcat中查找如下:
//DataSource ds = (DataSource)initCtx.lookup("java:/comp/env/jdbc/b2c");
//websphere中查找如下:
/////////////////////////////////////////////////////////////////////////
DataSource ds = (DataSource)initCtx.lookup("jdbc/shopping");
////////////////////////////////////////////////////////////////////////
con = ds.getConnection();
System.out.println("数据源连接成功");
} catch (NamingException e) {
e.printStackTrace();
throw new ServletException(e.getMessage());
} catch (SQLException e) {
e.printStackTrace();
throw new ServletException(e.getMessage());
}
return con;
}