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