Erro ao conectar com o banco de dados web

minha classe de conexão

public class ConnectionFactory {
public static Connection getConnection() {
try{
Class.forName(“org.postgresql.Driver”);//tenta achar a classe
} catch (ClassNotFoundException e) {
e.printStackTrace();//class not found exception
System.out.println("Erro ao carregar o Driver ");
}
try {
Connection conect = DriverManager.getConnection(“jdbc:postgresql://localhost:5435/vendasdb”,
“postgres”, “admin”);
JOptionPane.showMessageDialog(null, “Conected with database!”);
return conect;
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(“Failed to connect to the database”);
}
}
}

erro

java.lang.ClassNotFoundException: org.postgresql.Driver
Erro ao carregar o Driver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1280)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1114)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at br.com.vendasonline.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:14)
at br.com.vendasonline.jdbc.ClientDAO.(ClientDAO.java:18)
at Controllers.UserController.doPost(UserController.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1419)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:44)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5435/vendasdb
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at br.com.vendasonline.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:20)
at br.com.vendasonline.jdbc.ClientDAO.(ClientDAO.java:18)
at Controllers.UserController.doPost(UserController.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1419)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:44)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

pom

> <?xml version="1.0" encoding="UTF-8"?>
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
>     <modelVersion>4.0.0</modelVersion>

>     <groupId>br.com.vendasonline</groupId>
>     <artifactId>vendasdb</artifactId>
>     <packaging>war</packaging>
>     <version>1.0-SNAPSHOT</version>
>     <name>endasdb</name>
>     <url>http://maven.apache.org</url>
>     <dependencies>
>         <dependency>
>             <groupId>xerces</groupId>
>             <artifactId>xercesImpl</artifactId>
>             <version>2.9.1</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>org.postgresql</groupId>
>             <artifactId>postgresql</artifactId>
>             <version>9.4.1208.jre7</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.xbean</groupId>
>             <artifactId>xbean-reflect</artifactId>
>             <version>3.4</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.httpcomponents</groupId>
>             <artifactId>httpclient</artifactId>
>             <version>4.0.2</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>javax.servlet</groupId>
>             <artifactId>javax.servlet-api</artifactId>
>             <version>3.1.0</version>
>         </dependency>
>         <dependency>
>             <groupId>com.thoughtworks.xstream</groupId>
>             <artifactId>xstream</artifactId>
>             <version>1.3.1</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>xerces</groupId>
>             <artifactId>xercesImpl</artifactId>
>             <version>2.9.1</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>log4j</groupId>
>             <artifactId>log4j</artifactId>
>             <version>1.2.12</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>log4j</groupId>
>             <artifactId>log4j</artifactId>
>             <version>1.2.12</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>commons-lang</groupId>
>             <artifactId>commons-lang</artifactId>
>             <version>2.5</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>org.codehaus.plexus</groupId>
>             <artifactId>plexus-container-default</artifactId>
>             <version>1.5.5</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>log4j</groupId>
>             <artifactId>log4j</artifactId>
>             <version>1.2.12</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>org.mortbay.jetty</groupId>
>             <artifactId>jetty-util</artifactId>
>             <version>6.1.25</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.httpcomponents</groupId>
>             <artifactId>httpclient</artifactId>
>             <version>4.0.2</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>commons-lang</groupId>
>             <artifactId>commons-lang</artifactId>
>             <version>2.5</version>
>             <scope>test</scope>
>         </dependency>
>     </dependencies>
>     <build>
>         <finalName>vendasdb</finalName>
>         <plugins>
>             <plugin>
>                 <artifactId>maven-compiler-plugin</artifactId>
>                 <configuration>
>                     <source>1.8</source>
>                     <target>1.8</target>
>                 </configuration>
>             </plugin>
>         </plugins>
>     </build>
> </project>

uso o postgresql 9.4

Verifique se o jar do driver está entre as dependências e se o pacote org.postgresql contem a classe Driver. Pode ser que a versão esteja errada.

então leandro, o driver esta nas minhas dependencias como vc pode ver no pom.xml

        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4.1208.jre7</version>
    </dependency>

quando eu faço um teste para adicionarr um cliente por exemplo… eu coloquei um System.out.println(“carregou o driver”) dentro do try, pra ver se achava a classe Driver… e sempre aparece a mensagem que carregou o driver… porem quando é na web n acha…

Se você usa eclipse, (já vi que você não usa) clica com o direito no projeto e vá em propriedades -> deployment assembly -> Add. Adicione uma “Java build path entries” e selecione as dependências do maven. Isso deve ser suficiente.

Procure na sua IDE o recurso equivalente a esse. No Intellij eu não sei como fica…

Leandro, consegui resolver meu problema peo outro post… mas muito obrigado por me ajudar! vocÊ é fera