Me ajudem pls estou iniciando java com oracle to econtrando uma dificuldade

3 respostas
marcelinhonbs

ese é o codigo

import java.sql.*;

import java.net.PasswordAuthentication;

import oracle.jdbc.pool.OracleDataSource;
public class main {

public static void main(String[] args) throws SQLException {

Connection con = null;

String url;

String user;

String pass;

Statement stmt = null;
url = new String("jdbc:oracle:thin:@127.0.0.1:8080");
	user = new String("sys");
	pass = new String ("123");
	
	try{
		Class.forName("oracle.jdbc.driver.OracleDriver");
	}
	catch(java.lang.ClassNotFoundException e)
         {
                 System.err.print("ClassNotFoundException: ");
                 System.err.println(e.getMessage());
         }
	 try
     {

		con = DriverManager.getConnection(url,user,pass);   
		
		stmt = con.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT Codigo,Nome,EMAIL FROM tblCliente");
		
	System.out.print("Exibe a tabela");
	while(rs.next()){
		int i = rs.getInt("codigo"); 
		String s = rs.getString("Nome");
        String e = rs.getString("Email");
		          
        System.out.println(s + " " + i+""+ e);

	}
    System.out.println("\n");


	}
		
	catch(Exception e){
			System.out.println("Ocorreu um erro " + e.getMessage());
			System.out.println(0);
			
	}
	finally{
	stmt.close();
	con.close();
	}
	
	}
}

ese é o erro

Ocorreu um erro Exceção de E/S: Got minus one from a read call
Exception in thread “main” java.lang.NullPointerException
at main.main(main.java:53)

Vlw ae

3 Respostas

dkotvan

Cara,

O problema está na porta que vc está usando:

url = new String("jdbc:oracle:thin:@127.0.0.1:8080");

No Oracle normalmente é a porta 1521 onde fica o oracle:

url = new String("jdbc:oracle:thin:@127.0.0.1:1521");

Faça essa alteração e aí vai funcionar

marcelinhonbs

AGORA COM ESSA NOVA PORTA FICO APARECENDO ESTE ERRO ESTOU USANDO O ORACLE XE

Ocorreu um erro Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
The Connection descriptor used by the client was:
127.0.0.1:1521

marcelinhonbs

So passando pra agredece ja consegui

faltava “/XE” apos o numero da porta

Obrigado

abraços

xD

Criado 2 de agosto de 2008
Ultima resposta 3 de ago. de 2008
Respostas 3
Participantes 2