Postgres : No suitable Driver found for jdbc

Abhishek Singh picture Abhishek Singh · Aug 9, 2013 · Viewed 22.8k times · Source

I know this might be a possible duplicate of question posted here. Sorry for that.Here is the code i wrote for Database connection

 try{
            Class.forName("org.postgresql.Driver");     
       }

       catch(ClassNotFoundException e)
       {
          e.printStackTrace();
       }

       try{
           String URL = "jdbc:posgresql://localhost:5432/postgres";
           String USER = "postgres";
           String PASS = "postgres";
           Connection conn = DriverManager.getConnection(URL, USER, PASS);
           Statement st = conn.createStatement();
           ResultSet rs = st.executeQuery("Select * from employee");
           while(rs.next()){
               System.out.println(rs.getString(1));
           }

       }

       catch(SQLException es){
           es.printStackTrace();
       }

While running this code i get the following exception :

java.sql.SQLException: No suitable driver found for jdbc:posgresql://localhost:5432/postgres
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at ManageEmployee.main(ManageEmployee.java:60)

I have built this project in eclipse and added the external jar of postgres

Here is the .classpath file if it might help

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
        <attributes>
            <attribute name="owner.project.facets" value="java"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry kind="lib" path="//10.202.6.95/kavitha_share/jars/postgresql-8.2-504.jdbc2ee.jar"/>
    <classpathentry kind="output" path="build/classes"/>
</classpath>

what could be the possible reason as i have already added the jars ??

Answer

ihsan kocak picture ihsan kocak · Aug 9, 2013

Change posgresql to postgresql.

jdbc:posgresql://localhost:5432/postgres

becomes:

jdbc:postgresql://localhost:5432/postgres

Please note the character 't' in postgresql