Erro em conexao Postgres

6 respostas
C

ola, sou recem chegao ao java estava testando uma conexao com o bd Postgres no WIn XP

import java.sql.DriverManager;

import java.sql.Connection;

import java.sql.SQLException;
public class BD1 {

public static void main(String[] argv) {

System.out.println(Checking if Driver is registered with DriverManager.);
try {

Class.forName(org.postgresql.Driver);

} catch (ClassNotFoundException cnfe) {

System.out.println(Couldnt find the driver!);

System.out.println(Lets print a stack trace, and exit.”);

cnfe.printStackTrace();

System.exit(1);

}

System.out.println(“Registered the driver ok, so let’s make a connection.”);

Connection c = null;

try {

// The second and third arguments are the username and password,

// respectively. They should be whatever is necessary to connect

// to the database.

c = DriverManager.getConnection(“jdbc:postgresql://localhost/dellstore2,

dellstore2, dellstore2);

} catch (SQLException se) {

System.out.println(“Couldn’t connect: print out a stack trace and exit.);

se.printStackTrace();

System.exit(1);

}
if (c != null)

System.out.println(Hooray! We connected to the database!);

else

System.out.println(We should never get here.”);

}

}
e obtenho o seguintre erro:

Checking if Driver is registered with DriverManager.

Couldnt find the driver!

Lets print a stack trace, and exit.

java.lang.ClassNotFoundException: org.postgresql.Driver

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at BD1.main(BD1.java:10)

alguem aih pode me dizer onde esta o erro? e como solucioná-lo (lembre que sou pricipiante…)

6 Respostas

C

Você ja adicionou o conector .jar do seu driver no seu projeto???

C

Como faco isso

C

Qual a IDE que você está utilizando???

C

COmo sou principiante nao uso Nenhuma por ora. Uso apenas o Editor EditPlus (www.editplus.com).

C

Como você não está utilizando nenhuma você deverá adicionar ao seu classpath algumas coisas.

Você deve baixar da net o seu conector:
http://jdbc.postgresql.org/download/postgresql-8.2dev-503.jdbc2.jar

Depois deverá colocar dentro da pasta Java instalada.

Que no meu caso é:

C:\Arquivos de programas\Java\jdk1.5.0_07\jre\lib\ext

obs: sua pasta pode estar num local diferente, cuidado.

Setar no seu classpath essa pasta.

Exemplo:

C:\Arquivos de programas\Java\jdk1.5.0_07\jre\lib\ext\postgresql-8.2dev-503.jdbc2.jar

C

problema resolvido
1 - classpath setado nas variaveis de ambiente
2 - no trecho
c = DriverManager.getConnection(“jdbc:postgresql://localhost/dellstore2”…)

o correto era
c = DriverManager.getConnection(“jdbc:postgresql:dellstore2”)

Mto agradecido.
Aparece lah em casa qdo puder pra gente tomar uma cafezinho
e discutir
ashausahus
Akele Abraco

Criado 16 de setembro de 2006
Ultima resposta 21 de set. de 2006
Respostas 6
Participantes 2