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?
– romarcio
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)
– Marcus Vinicius
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)
– Marcus Vinicius
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)
– Marcus Vinicius
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)
– Marcus Vinicius
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)
– Marcus Vinicius
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.
– Marcus Vinicius