The infamous java.sql.SQLException: No suitable driver found

前端 未结 16 1517
广开言路
广开言路 2020-11-21 05:10

I\'m trying to add a database-enabled JSP to an existing Tomcat 5.5 application (GeoServer 2.0.0, if that helps).

The app itself talks to Postgres just fine, so I kn

16条回答
  •  梦如初夏
    2020-11-21 05:27

    I faced the similar issue. My Project in context is Dynamic Web Project(Java 8 + Tomcat 8) and error is for PostgreSQL Driver exception: No suitable driver found

    It got resolved by adding Class.forName("org.postgresql.Driver") before calling getConnection() method

    Here is my Sample Code:

    try {
                Connection conn = null;
                Class.forName("org.postgresql.Driver");
                conn = DriverManager.getConnection("jdbc:postgresql://" + host + ":" + port + "/?preferQueryMode="
                        + sql_auth,sql_user , sql_password);
            } catch (Exception e) {
                System.out.println("Failed to create JDBC db connection " + e.toString() + e.getMessage());
            }
    

提交回复
热议问题