收到以下错误-未找到适用于jdbc的驱动程序:postgresql:// localhost:5432 / testDBMS [英] Getting the following error - No suitable driver found for jdbc:postgresql://localhost: 5432/testDBMS

查看:659
本文介绍了收到以下错误-未找到适用于jdbc的驱动程序:postgresql:// localhost:5432 / testDBMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我返回一条错误消息,指出java.sql.SQLException:没有找到适合的驱动程序

jdbc:postgresql:// localhost:
5432 / testDBMS

I get back an error indicating java.sql.SQLException: No suitable driver found for
jdbc:postgresql://localhost: 5432/testDBMS

import java.sql.*;
import java.util.*;

public class JdbcPostgresqlConnection {

    public static void main(String[] args) {
    Connection conn3 = null;

    try {
        String dbURL3 = "jdbc:postgresql://localhost:5432/testDBMS";
        Properties parameters = new Properties();
            parameters.put("user", "pgmrHere");
            parameters.put("password", "111111");
        conn3 = DriverManager.getConnection(dbURL3, parameters);
    }
    catch (SQLException ex) { ex.printStackTrace(); }
  }
}


推荐答案

java -cp . JdbcPostgresqlConnection

因此,很明显,类路径中唯一的东西是当前目录()。 postgresql驱动程序jar不是。您需要将其添加到类路径中:

So, clearly, the only thing that is in the classpath is the current directory (.). The postgresql driver jar is not. You need to add it to the classpath:

java -cp .:/path/to/driver.jar JdbcPostgresqlConnection

在Linux / MacOS上,或

on Linux/MacOS, or

java -cp .;c:\path\to\driver.jar JdbcPostgresqlConnection

在Windows上。

这篇关于收到以下错误-未找到适用于jdbc的驱动程序:postgresql:// localhost:5432 / testDBMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆