I can not connect jsp page to Oracle database

1
  

This my Web project worked in school, but in my pc will not ..   It was to return "connected in the oracle database" and it returns   "oracle.jdbc.driver.OracleDriver"

     

Connection class:

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();
        }
    }
}
  

Page Code: jsp:

<%@ 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>
  

Rodo it with Tomcat v7.0 I referenced the jdbc6, jtds-1.2.5 and classes12

     

Note: another Java project connected normal to the bank

    
asked by anonymous 04.11.2017 / 20:29

2 answers

0

I had the problem again with no acknowledgment, and I put jtds and ojdbc6 directly into the apache tomcat lib folder and removing old references to avoid duplication of libraries. And in doing all that, I saved and restarted the eclipse. This time it worked with jdk 1.8 with no problems.

    
04.01.2019 / 14:27
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: link

View your bank version and download the driver for it.

If you have already done so, then it may be that the driver is not in your IDE build. If you use eclipse, go to the lib folder by the project tree and right click on the driver. There will be an option to include in the build, 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 one in tomcat. Hence the ideal is to remove one of them.

    
06.11.2017 / 17:11