edabruzzo / Projeto_UNINOVE-MVC-JDBC

PROJETO CRIADO PARA A MATÉRIA PROGRAMAÇÃO ORIENTADA A OBJETOS
0 stars 0 forks source link

Problema na configuração do DataSource no GlassFish na view usuarioTESTES.jsp #6

Open edabruzzo opened 6 years ago

edabruzzo commented 6 years ago

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

GlassFish não encontra o driver JDBC do MySQL

Possíveis soluções :

Admin-gui do GlassFish : localhost:4848 configuração dos datasources : %GLASSFISH_HOME%/s/glassfish-4.1.1/glassfish/domains/domain1/config/domain.xml

https://javatutorial.net/configure-glassfish-mysql

https://stackoverflow.com/questions/17378840/glassfish-no-suitable-driver-for-mysql-when-trying-to-connect-with-datasource

https://stackoverflow.com/questions/25088991/javax-servlet-jsp-jspexception-unable-to-get-connection-datasource-invalid-j

edabruzzo commented 6 years ago

**Coloquei uma cópia do arquivo "mysql-connector-java-5.1.23-bin.jar" no seguinte diretório:

C:\Program Files\Java\jdk1.8.0_151\lib C:\Program Files\Java\jre1.8.0_161\lib\ext NÃO CHEGUEI A TESTAR Tirei os jars do driver Mysql das pastas lib das pastas do JAVA.

edabruzzo commented 6 years ago

Colocando o jar do driver JDBC do Mysql nos seguintes locais:

C:\Program Files\glassfish-4.1.1\glassfish\lib\deployment C:\Program Files\glassfish-4.1.1\glassfish\lib

edabruzzo commented 6 years ago

Colocando o jar do driver JDBC do Mysql nos seguintes locais:

C:\Users\Emm\AppData\Roaming\NetBeans\8.2\config\GF_4.1.1\domain1\lib\ext

Após, reinicei o NetBeans

edabruzzo commented 6 years ago

image

Pela tela de administração do GlassFish mudei o Resource Type do Pool para java.sql.Driver e no class Name coloquei o nome da classe do driver Mysql "com.mysql.jdbc.Driver"

Após, tentei salvar. Ele dá um erro dizendo que não pode fazer um cast de Driver para java.sql.Dasource

Após isso, eu voltei para java.sql.DataSource e dei um ping no banco. Ele conseguiu fazer a conexão pelo admin-gui (localhost:4848).

edabruzzo commented 6 years ago

https://docs.oracle.com/cd/E26576_01/doc.312/e24929/deploying-applications.htm#GSDPG00075

https://docs.oracle.com/cd/E26576_01/doc.312/e24929/dd-files.htm#GSDPG00006

edabruzzo commented 6 years ago

https://stackoverflow.com/questions/19530730/how-to-deploy-a-webapp-and-create-its-resources

edabruzzo commented 6 years ago

NÃO ACHA O DRIVER DE JEITO NENHUM !!

Tentativa:coloquei o driver na seguinte pasta : C:\Program Files\glassfish-4.1.1\glassfish\lib\ext

edabruzzo commented 6 years ago

Tentando registrar o driver no método doGet do ServletController:


 @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(UsuariosServletController.class.getName()).log(Level.SEVERE, null, ex);
        }
edabruzzo commented 6 years ago

Verifiquei que o JAR do Driver JDBC do MySQL que adicionei pelo NetBeans era um Binário. Retirei ele do projeto e troquei por um JAR normal.

edabruzzo commented 6 years ago

Adicionei o mysql-connector-java-5.1.23.jar e NÃO !!!! o mysql-connector-java-5.1.23-bin.jar no seguinte caminho: C:\Users\Emm\AppData\Roaming\NetBeans\8.2\config\GF_4.1.1\domain1\lib\ext

edabruzzo commented 6 years ago

Mudando para o Apache Tomcat. Neste caso, os recursos ficam no arquivo context.xml na pasta META-INF.

Já no caso do GlassFish os recursos ficam no arquivo glassfish-resources.xml na pasta WEB-INF.

Lembrando que a sintaxe do arquivo context.xml do Tomcat é diferente da sintaxe do glassfish-resource.xml do GlassFish.

edabruzzo commented 6 years ago

No Tomcat é possível ver que o driver não está sendo registrado para ser usado pelo JSP:

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"

edabruzzo commented 6 years ago

Coloquei o jar do driver Mysql na pasta lib do Tomcat

edabruzzo commented 6 years ago

Deixando o driver somente na pasta lib do Tomcat

edabruzzo commented 6 years ago
HTTP Status 500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"

type Exception report

message javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"

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

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:561)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:462)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    Controller.UsuariosServletController.doGet(UsuariosServletController.java:78)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    Util.FiltroJDBC.doFilter(FiltroJDBC.java:80)

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
    org.apache.jsp.WEB_002dINF.view.usuarioTESTES_jsp._jspService(usuarioTESTES_jsp.java:166)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    Controller.UsuariosServletController.doGet(UsuariosServletController.java:78)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    Util.FiltroJDBC.doFilter(FiltroJDBC.java:80)

root cause

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"
    org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:318)
    org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:201)
    org.apache.jsp.WEB_002dINF.view.usuarioTESTES_jsp._jspx_meth_sql_005fquery_005f0(usuarioTESTES_jsp.java:190)
    org.apache.jsp.WEB_002dINF.view.usuarioTESTES_jsp._jspService(usuarioTESTES_jsp.java:122)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    Controller.UsuariosServletController.doGet(UsuariosServletController.java:78)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    Util.FiltroJDBC.doFilter(FiltroJDBC.java:80)