Java Postgres:找不到适合 jdbc 的驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18142711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:42:46  来源:igfitidea点击:

Postgres : No suitable Driver found for jdbc

javapostgresqljdbcclasspatheclipse-classpath

提问by Abhishek Singh

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

我已经在 eclipse 中构建了这个项目并添加了 postgres 的外部 jar

Here is the .classpath file if it might help

如果可能有帮助,这是 .classpath 文件

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

我已经添加了罐子,可能的原因是什么??

采纳答案by ihsan kocak

Change posgresqlto postgresql.

更改posgresqlpostgresql

jdbc:posgresql://localhost:5432/postgres

becomes:

变成:

jdbc:postgresql://localhost:5432/postgres

Please note the character 't' in postgresql

请注意pos tgresql中的字符' t'