Postgres : No suitable Driver found for jdbc

岁酱吖の 提交于 2019-12-07 04:56:55

问题


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 ??


回答1:


Change posgresql to postgresql.

jdbc:posgresql://localhost:5432/postgres

becomes:

jdbc:postgresql://localhost:5432/postgres

Please note the character 't' in postgresql



来源:https://stackoverflow.com/questions/18142711/postgres-no-suitable-driver-found-for-jdbc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!