Basta adicionar as linhas no codigo abaixo (estao marcadas com >>)
 
----- Original Message -----
Sent: Tuesday, November 20, 2001 4:03 PM
Subject: [java-list] Problemas com conexao

Amigos, criei uma classe para conectar o Oracle e esta dando problemas. Alguem poderia me sugerir como corrigir?
 
class Conectar {
 
 String strUrl;
 String strUsuario;
 String strSenha;
 Connection conexao;
 
 public Connection conexaoUniban(boolean blnConexaoParaProducao)  {
 
  if (blnConexaoParaProducao == true)  {
   this.strUrl = "jdbc: odbc: TESTE_MC";
   this.strUsuario = "teste";
   this.strSenha = "teste";
  }
  else if (blnConexaoParaProducao == false)  {
   this.strUrl = "jdbc: odbc: TESTE_DESENV";
   this.strUsuario = "testedesenv";
   this.strSenha = "testedesenv";
  }
>>  try
>>{  
    Class.forName("oracle.jdbc.driver.OracleDriver");  
    conexao = DriverManager.getConnection(this.strUrl, this.strUsuario, this.strSenha);
>>}
>>catch(ClassNotFoundException cnf)
>>{
>>  cnf.printStackTrace();
>>}
>>catch(SQLException e)
>>{
>>  e.printStackTrace();
>>}
     
  return conexao;
 }
 
 public Conectar () {
 
 }
 
}
 
O erros foram os seguintes na compilação:
 

OlaInternet.java:27: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown

Class.forName("oracle.jdbc.driver.OracleDriver");

^

OlaInternet.java:28: unreported exception java.sql.SQLException; must be caught or declared to be thrown

conexao = DriverManager.getConnection(this.strUrl, this.strUsuario, this.strSenha);

Agradeço desde já pela ajuda

 

Jefferson

Responder a