I cannot connect jsp page to Oracle bank

Asked

Viewed 189 times

1

This Web project of mine worked at school, but on my computer it won’t.. It was to return "connected in the oracle database" and returns "oracle.jdbc.driver.Oracledriver "

Code class connection:

package classeConexao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import oracle.jdbc.pool.OracleDataSource;

public class Conexao 
{
    private String URL     = "";   
    private String DRIVER  = "";
    private String USUARIO = "";
    private String SENHA   = "";
    private String BANCO   = "ORACLE";

    public void SelectBD(String Banco)
    {
        BANCO = Banco;
        if (BANCO.equals("SQL"))
        {   
            //CONEXAO SQL EXPRESS 
            URL     = "jdbc:jtds:sqlserver://localhost:1433/BancoSQL;";
            DRIVER  = "net.sourceforge.jtds.jdbc.Driver";
            USUARIO = "sa";
            SENHA   = "123456";
        }
        else if(BANCO.equals("ORACLE"))
        {
            //CONEXAO ORACLE EXPRESS
            URL     = "jdbc:oracle:thin:@localhost:1521:xe";
            DRIVER  = "oracle.jdbc.driver.OracleDriver";
            USUARIO = "android"; //"sys as sysdba";
            SENHA   = "123456";
        }
    }

    public Statement ponte;
    public String status = "";
    public String getStatus() 
    {
        return status;
    }

        public Conexao()
    {
        try {
            System.out.println("Banco "+ BANCO);
            SelectBD(BANCO);
            if (BANCO.equals("SQL"))
            {   
                Class.forName(DRIVER);
                Connection con;
                con = DriverManager.getConnection(URL,USUARIO,SENHA);
                ponte = con.createStatement();
            }
            else if(BANCO.equals("ORACLE"))
            {
                Class.forName(DRIVER);
                Connection con;
                OracleDataSource ds;
                ds = new OracleDataSource();
                ds.setURL(URL);
                con = ds.getConnection(USUARIO,SENHA);
                ponte = con.createStatement();
            }
            status = "Conectado no banco " + BANCO + "!!!" ;
        } catch (Exception e) {
            status = e.getMessage();
            e.printStackTrace();
        }
    }

    public void manutencao(String sql)
    {
        try {
            ponte.executeUpdate(sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Code of jsp page:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="classeConexao.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>AULA DE TEEM - Integrando soluções!</title>
</head>
<body>
<center>
<h2>CADASTRO - Lista de Contatos</h2>
<hr>
<a href="listagem.jsp">Listagem dos Contatos</a>
<hr>
<%
Conexao conexao = new Conexao();

 out.println(conexao.getStatus());
%>
<hr>
</center>
</body>
</html>

I run it with Tomcat v7.0 Referenciei ojdbc6, jtds-1.2.5 and classes12

Note: Another Java project connected normal to the database

  • And there are some exceptions in the log?

  • Oraclejava.lang.Classnotfoundexception: oracle.jdbc.driver.Oracledriver at org.apache.Catalina.loader.Webappclassloader.loadClass(Webappclassloader.java:1720) at org.apache.Catalina.loader.Webappclassloader.loadClass(Webappclassloader.java:1571) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at classeConexao.Conexao. <init>(Connected.java:58) at org.apache.jsp.index_jsp. _jspService(index_jsp.java:78) at org.apache.Jasper.runtime.Httpjspbase.service(Httpjspbase.java:70) at javax.servlet.http.HttpServlet.service(Httpservlet.java:727)

  • at org.apache.Jasper.servlet.Jspservletwrapper.service(Jspservletwrapper.java:432) at org.apache.Jasper.servlet.Jspservlet.serviceJspFile(Jspservlet.java:395) at org.apache.Jasper.servlet.Jspservlet.service(Jspservlet.java:339) at javax.servlet.http.HttpServlet.service(Httpservlet.java:727) at org.apache.Catalina.core.Applicationfilterchain.internalDoFilter(Applicationfilterchain.java:303) at org.apache.Catalina.core.Applicationfilterchain.doFilter(Applicationfilterchain.java:208) at org.apache.Tomcat.websocket.server.WsFilter.doFilter(Wsfilter.java:52)

  • at org.apache.Catalina.core.Applicationfilterchain.internalDoFilter(Applicationfilterchain.java:241) at org.apache.Catalina.core.Applicationfilterchain.doFilter(Applicationfilterchain.java:208) at org.apache.Catalina.core.Standardwrappervalve.invoke(Standardwrappervalve.java:220) at org.apache.Catalina.core.Standardcontextvalve.invoke(Standardcontextvalve.java:122) at org.apache.Catalina.authenticator.Authenticatorbase.invoke(Authenticatorbase.java:503) at org.apache.Catalina.core.Standardhostvalve.invoke(Standardhostvalve.java:170)

  • at org.apache.Catalina.valves.Errorreportvalve.invoke(Errorreportvalve.java:103) at org.apache.Catalina.valves.Accesslogvalve.invoke(Accesslogvalve.java:950) at org.apache.Catalina.core.Standardenginevalve.invoke(Standardenginevalve.java:116) at org.apache.Catalina.connector.Coyoteadapter.service(Coyoteadapter.java:421) at org.apache.Coyote.http11.Abstracthttp11processor.process(Abstracthttp11processor.java:1070) at org.apache.Coyote.Abstractprotocol$Abstractconnectionhandler.process(Abstractprotocol.java:611)

  • at org.apache.Tomcat.util.net.Jioendpoint$Socketprocessor.run(Jioendpoint.java:314) at java.util.Concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.Concurrent.Threadpoolexecutor$Worker.run(Unknown Source) at org.apache.Tomcat.util.threads.Taskthread$Wrappingrunnable.run(Taskthread.java:61) at java.lang.Thread.run(Unknown Source)

  • jtds and ojdbc6 drivers were used in Eclipse Luna, and I couldn’t create a jsp page on it. So I downloaded another one. I don’t know if it’s tbm.

Show 2 more comments

2 answers

0

According to the exception you posted

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

the application is not finding the Oracle jdbc driver. You can download it from this page: http://www.oracle.com/technetwork/database/application-development/survey/index.html

See the version of your bank and download the driver.

If you have already done so, then the driver may not be in the build of your ide. If you use the eclipse, go to the lib folder by the project tree and right-click on the driver. An option to include in the build will appear, click on it.

Another situation that could result in this error is the conflict between libraries. For example, two different versions of the driver, for example, one in the application and the other in Tomcat. Hence the ideal is to remove one of them.

  • tried the three options and nothing

  • I reviewed your post and saw that you quoted it "I run it with Tomcat v7.0 Referenciei ojdbc6, jtds-1.2.5 and classes12". Remove this library classes12, I think it is she who is causing the conflict. It was used as oracle dirver before version 1.3 of Java.

  • my jre1.8.0_144 and my jdk1.8.0_144, will the jdbc I have to have is the ojdbc8?

  • now appeared this "The superclass "javax.servlet.http.Httpservlet" was not found on the Java Build Path"

  • together with ---------------------------------------------------------Oracle Database java.sql.Sqlexception: Invalid Oracle URL specified at oracle.jdbc.driver.DatabaseError.throwSqlException(Databaseerror.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(Databaseerror.java:146)

  • javax.servlet.http.HttpServlet points to the lack of the Servlet api. You can get it at https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/3.1.0. If you already have it among your libraries, then you missed adding it in the IDE build, the process I mentioned earlier that you would have to do with the connection driver.

  • About the database error, it seems your database access URL has some error. At least that’s what the exception is saying. What version of the Oracle driver are you using? Continue with 6 or switched to 8?

  • I tried all this and configured the Tomcat Server again excluding the others.. And I also noticed that when creating the server, I had an alert saying that the project facets would not run with jre1.8. I changed in project properties - project facets - java - ai clicked on the arrow changed from 1.8 to 1.7. I had already installed jre1.7.. It worked. Thanks!!!

Show 3 more comments

0


I had the problem again with non-recognition, and I put jtds and ojdbc6 directly in the lib folder of apache Tomcat and removing old references to avoid library duplicates. And by doing all this, I saved and restarted the eclipse. This time it worked with jdk 1.8 without any problems.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.