无法使用Netbeans创建与GlassFish数据库的连接?

时间:2015-09-14 18:30:39

标签: java mysql netbeans web-applications netbeans-8.1

我正在使用Netbeans 8.1 beta和Glassfish服务器4.1,Mysql。

每次我在Webapplication与数据库之间建立连接时都无法实现。

Index.jsp文件:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%-- 
    Document   : index
    Created on : Sep 14, 2015, Sep 14, 2015 12:48:03 AM
    Author     : ESAJ
--%>
<link rel="stylesheet" type="text/css" href="style.css">



<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Samir</title>
    </head>
    <body>
        <h1><span style="color:#FF0000;">IFPWAFCAD</span></h1>
        <table border="0">
            <thead>
                <tr>
                    <th>IFPWAFCAD offers expert counseling in a wide range of fields.</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <form action="response.jsp">
                            <strong>Select a subject:</strong>
                        </form>
                        <select name="subject_id">
                            <option></option>
                            <option></option>
                        </select>
                        <input type="submit" value="submit" />
                    </td>
                </tr>
                <tr>
                    <td>To view the contact details of an IFPWAFCAD certified former
                        professional wrestler in your area, select a subject below:</td>
                </tr>
            </tbody>
        </table>
        <sql:query var="subject" dataSource="jdbc/IFPWAFCAD">
            SELECT subject_id, name FROM Subject
        </sql:query>
        <table border="1">
            <!-- column headers -->
            <tr>
                <c:forEach var="columnName" items="${subjects.columnNames}">
                    <th><c:out value="${columnName}"/></th>
                    </c:forEach>
            </tr>
            <!-- column data -->
            <c:forEach var="row" items="${subjects.rowsByIndex}">
                <tr>
                    <c:forEach var="column" items="${row}">
                        <td><c:out value="${column}"/></td>
                    </c:forEach>
                </tr>
            </c:forEach>
        </table>
    </body>
</html>

Glassfish resources.xml fiel:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
  <jdbc-resource enabled="true" jndi-name="jdbc/IFPWAFCAD" object-type="user" pool-name="IfpwafcadPool">
    <description/>
  </jdbc-resource>
  <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="IfpwafcadPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.ConnectionPoolDataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
    <property name="URL" value="jdbc:mysql://localhost:3306/mynewdatabase?zeroDateTimeBehavior=convertToNull"/>
    <property name="User" value="root"/>
    <property name="Password" value="admin"/>
  </jdbc-connection-pool>
</resources>

我已经将Jar文件复制到glassfish lib,我也已经添加了对web.xml的引用。

我遇到这个错误:

description 服务器遇到内部错误,无法完成此请求。

例外

  

javax.servlet.ServletException:javax.servlet.jsp.JspException:Unable   为了获得连接,DataSource无效:“java.sql.SQLException:No   找到适合jdbc / IFPWAFCAD的驱动程序“

根本原因

  

javax.servlet.jsp.JspException:无法获得连接,DataSource   无效:“java.sql.SQLException:找不到合适的驱动程序   JDBC / IFPWAFCAD“

2 个答案:

答案 0 :(得分:1)

看起来你缺少MySql的jdbc驱动程序。从这里下载

http://dev.mysql.com/downloads/connector/j/

将mysql-connector-java-5.x.xx-bin.jar解压缩并复制到$ glassfish_install_folder \ glassfish \ lib

用户正确的驱动程序匹配jdk和mysql版本u正在使用以避免错误。

答案 1 :(得分:0)

经过几个小时的努力让Netbeans(8.2)与Glassfish,特别是JDBC合作,我放弃了Glassfish,因为我意识到它已停止使用。而安装Payara似乎是一个分叉。很简单,只需在Netbeans中使用Glassfish设置,只需指向一个新的方向即可。 要显示连接池和JDBC资源,请右键单击Netbeans中的服务器,转到Paraya的管理控制台,然后选择“View Domain Admin Control”。转到JDBC连接池并手动添加“IpwafcadPool”。请记住为User(root)和Password(root)添加属性。 URL有两个属性,一个是大写,一个是小写。我将两者都更改为jdbc:mysql:// localhost:3306 / MyNewDatabase?zeroDateTimeBehavior = convertToNull。

但是对于上述问题。我可以确认连接器驱动程序必须更新到最新版本。我尝试使用mysql-connector-java-5.1.40-bin.jar(在lib文件夹中),重新启动Paraya,现在它就像一个魅力。现在我可以继续学习教程https://netbeans.org/kb/docs/web/mysql-webapp.html。是的,我通过排除故障了解了很多,谢谢你。

相关问题