无法使用Netbeans创建到GlassFish数据库的连接? [英] Unable to create connection to GlassFish database with Netbeans?

查看:79
本文介绍了无法使用Netbeans创建到GlassFish数据库的连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netbeans 8.1 beta和Glassfish服务器4.1(Mysql).

I'm using Netbeans 8.1 beta and Glassfish server 4.1, Mysql.

每次我在Web应用程序与数据库之间创建连接时,它都无法连接.

Every time I create connection between my Webapplication with database it's unable to do it.

Index.jsp文件:

Index.jsp file:

<%@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文件:

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的引用.

I already copy the Jar file to glassfish lib, also I already add reference to web.xml.

我遇到此错误:

描述:服务器遇到内部错误,无法满足该请求.

description The server encountered an internal error that prevented it from fulfilling this request.

例外

javax.servlet.ServletException:javax.servlet.jsp.JspException:无法 要获得连接,数据源无效:"java.sql.SQLException:否 找到了适用于jdbc/IFPWAFCAD的驱动程序"

javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/IFPWAFCAD"

根本原因

javax.servlet.jsp.JspException:无法获得连接,数据源 无效:"java.sql.SQLException:找不到适合的驱动程序 jdbc/IFPWAFCAD"

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/IFPWAFCAD"

推荐答案

看起来像u缺少MySql的jdbc驱动程序.从这里下载

Looks like u are missing jdbc driver for MySql. Download it from here

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

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

unzip and copy mysql-connector-java-5.x.xx-bin.jar it into $glassfish_install_folder\glassfish\lib

使用与jdk和mysql版本u相匹配的用户适当的驱动程序来避免错误.

User proper driver which match jdk and mysql version u are using to avoid errors.

这篇关于无法使用Netbeans创建到GlassFish数据库的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆