jeveauxPJ 11 de mai. de 2007
Opa Thiago,
Cara, você poderia descrever melhor o teu erro? Coloca ae a mensagem de erro que apareceu pra você, já ajuda bastante. Em todo caso, se um exemplo de classe para conexão com Oracle que tu pode usar.
import java.sql.Connection ;
import java.sql.DriverManager ;
import java.sql.SQLException ;
public final class ConnectionOracle & # 123 ;
private ConnectionOracle & # 40 ; & # 41 ; & # 123 ;
super & # 40 ; & # 41 ;;
& # 125 ;
private final static String url = & quot ; jdbc & # 58 ; oracle & # 58 ; thin & # 58 ; @ENDERECO_DO_SEU_SERVIDOR & # 58 ; PORTA & # 58 ; BASE_DE_DADOS & quot ;;
private final static String driver = & quot ; oracle . jdbc . driver . OracleDriver & quot ;;
private final static String usuario = & quot ; usuario & quot ;;
private final static String senha = & quot ; senha & quot ;;
public static Connection getConnection & # 40 ; & # 41 ; throws SQLException & # 123 ;
try & # 123 ;
Class . forName & # 40 ; driver & # 41 ;;
return DriverManager . getConnection & # 40 ; url , usuario , senha & # 41 ;;
& # 125 ; catch & # 40 ; ClassNotFoundException e & # 41 ; & # 123 ;
e . printStackTrace & # 40 ; & # 41 ;;
return null ;
& # 125 ;
& # 125 ;
public static void freeConnection & # 40 ; Connection c & # 41 ; throws SQLException & # 123 ;
if & # 40 ; c != null & # 41 ; c . close & # 40 ; & # 41 ;;
& # 125 ;
& # 125 ;
thiaguinhocs2PJ 11 de mai. de 2007
Olá Jeveaux,
Obrigado por me responder.
Eis o erro:
Teste de Conexão!
java .sql .SQLException : Exce ção de E / S : The Network Adapter could not establish the connection
at oracle .jdbc .driver .DatabaseError .throwSqlException ( DatabaseError .java :138 )
at oracle .jdbc .driver .DatabaseError .throwSqlException ( DatabaseError .java :175 )
at oracle .jdbc .driver .DatabaseError .throwSqlException ( DatabaseError .java :287 )
at oracle .jdbc .driver .T4CConnection .logon ( T4CConnection .java :328 )
at oracle .jdbc .driver .PhysicalConnection .< init > ( PhysicalConnection .java :430 )
at oracle .jdbc .driver .T4CConnection .< init > ( T4CConnection .java :151 )
at oracle .jdbc .driver .T4CDriverExtension .getConnection ( T4CDriverExtension .java :32 )
at oracle .jdbc .driver .OracleDriver .connect ( OracleDriver .java :608 )
at java .sql .DriverManager .getConnection ( DriverManager .java :525 )
at java .sql .DriverManager .getConnection ( DriverManager .java :171 )
at Conexao .Conexao .abreConexao ( Conexao .java :18 )
at Conexao .Conexao .main ( Conexao .java :28 )
Process exited with exit code 0 .
thiaguinhocs2PJ 11 de mai. de 2007
Eu gostaria de saber se o problema está ocorrendo por que o servidor não é localhost…é um host externo…
Eis minha classe de conexão:
package Conexao;
import java.sql.Connection ;
import java.sql.DriverManager ;
import java.sql.SQLException ;
public class Conexao {
private final static String url = “ jdbc : oracle : thin : @endereçodohost : porta : xxx ” ;
private final static String driver = “ oracle . jdbc . OracleDriver ” ;
private final static String usu = “ xxx ” ;
private final static String senha = “ xxx ” ;
private static Connection conexao = null ;
public static Connection abreConexao () throws SQLException {
try {
Class . forName ( driver );
conexao = DriverManager . getConnection ( url , usu , senha );
} catch ( ClassNotFoundException e ){
e . printStackTrace ();
}
return conexao ;
}
public static void main ( String [] args ){
System . out . println ( "Teste de Conexão!" );
try {
System . out . println ( "Nome: " + ( Conexao . abreConexao ()). getCatalog ());
System . out . println ( "Classe: " + ( Conexao . abreConexao (). getClass ()));
} catch ( SQLException e ){
e . printStackTrace ();
}
}
}
thiaguinhocs2PJ 14 de mai. de 2007
Bom pessoal consegui resolver meu problema…
Caso alguém tenha o mesmo problema a resposta é a seguinte:
O meu URL estava errado…eis a cerração:
package Conexao;
import java.sql.Connection ;
import java.sql.DriverManager ;
import java.sql.SQLException ;
public class Conexao {
private final static String url = “ jdbc : oracle : thin : @ //endereçodohost:porta/nomedobanco”;
private final static String driver = “ oracle . jdbc . OracleDriver ” ;
private final static String usu = “ xxx ” ;
private final static String senha = “ xxx ” ;
private static Connection conexao = null ;
public static Connection abreConexao () throws SQLException {
try {
Class .forName ( driver ) ;
conexao = DriverManager .getConnection ( url ,usu ,senha ) ;
}catch ( ClassNotFoundException e ) {
e .printStackTrace () ;
}
return conexao ;
}
public static void main ( String [] args ){
System . out . println ( “ Teste de Conexão ! ” );
try {
System . out . println ( "Nome: " + ( Conexao . abreConexao ()). getCatalog ());
System . out . println ( "Classe: " + ( Conexao . abreConexao (). getClass ()));
}catch(SQLException e){
e.printStackTrace();
}
}
}