Glasshfish jndi查找失败

时间:2018-04-09 11:57:47

标签: java netbeans-8.2 glassfish-5

我是堆叠的新手,这是我的第一篇文章,如果我做错了,那就很抱歉。 我正在尝试将我的glassfish 5服务器与NetBeans 8.2中的MySQL数据库连接,但每次我尝试部署我的Web应用程序时,glassfish控制台都会给我

Exception while deploying the app [appname]: JNDI lookup failed for the resource: Name: [appnamePU], Lookup: [java:app/jdbc_blogdb], Type: [javax.sql.DataSource]


我尝试在glassfish管理面板上重新配置JDBC连接池,但在重新启动服务器后,它总是返回此异常。我正在使用JDBC资源和glassfish-resources.xml文件粘贴glassfish管理面板的屏幕截图。你有什么想法,为什么glassfish不想与我的数据库合作?

glassfish-resources.xml

JDBC Connection Pools

JDBC Resource

Full error from netbeans

[编辑]
我忘了添加,只有当我尝试运行和部署我的Web应用程序时才会显示此错误

2 个答案:

答案 0 :(得分:0)

您需要在代码中使用此子上下文来查找 -

java:comp/env/jdbc/jdbc_blogdb

答案 1 :(得分:0)

在您的glassfish-resources.xml中添加:

SELECT COUNT(*) vouchersleft, `prod_name`,
        `start_date`, 
        `end_date`,
        `reg_price`,
        `sale_price`,
        bbp.`prod_id`,
        `vouch_limits`,
        `sp_name`,
        `order_id`,
        `img_name`,
        `outlets`
        FROM `vouchers` as `v`
        INNER JOIN `bb_products` as `bbp` ON bbp.`prod_id` = v.`product_id`
        INNER JOIN `service_providers` as `sp` ON sp.`service_provider_id` = bbp.`provider_id`
        INNER JOIN `prod_pics` as `pp` ON pp.`prod_id` = bbp.`prod_id`
        INNER JOIN (SELECT COUNT(DISTINCT `outlet_id`) AS `outlets` FROM `prod_outlets` GROUP BY `product_id`) as `po` ON po.`product_id` = bbp.`prod_id`
        WHERE `frontend` = :frontend
        AND bbp.`featured` = :featured
        AND `order_id` = :order_id
        AND pp.`featured` = :featured_img
        GROUP BY bbp.`prod_id`

并确保已安装jdbc jar。万一您不知道是否有。将您的mysql jdbc jar放入glassfish- [VERSION] \ glassfish \ domains \ domain1 \ lib \ ext

通常,glassfish会将默认域创建为domain1……如果您更改了默认域,请使用您的域为“ domain1”