gpt4 book ai didi

java - Postgres : No suitable Driver found for jdbc

转载 作者:搜寻专家 更新时间:2023-10-31 08:11:03 25 4
gpt4 key购买 nike

我知道这可能与此处发布的问题重复。抱歉。这是我为数据库连接编写的代码

 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();
}

运行此代码时出现以下异常:

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)

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

这是 .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>

可能是什么原因,因为我已经添加了 jar ??

最佳答案

posgresql 更改为 postgresql

jdbc:posgresql://localhost:5432/postgres

变成:

jdbc:postgresql://localhost:5432/postgres

请注意postgresql

中的字符' t'

关于java - Postgres : No suitable Driver found for jdbc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18142711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com