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

前端 未结 16 1529
广开言路
广开言路 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:33

    In my case I was working on a Java project with Maven and encountered this error. In your pom.xml file make sure you have this dependencies

    
        
          junit
          junit
          4.11
          test
        
        
          mysql
          mysql-connector-java
          8.0.11
        
      
    

    and where you create connection have something like this

    public Connection createConnection() {
            try {
                String url = "jdbc:mysql://localhost:3306/yourDatabaseName";
                String username = "root"; //your my sql username here
                String password = "1234"; //your mysql password here
    
                Class.forName("com.mysql.cj.jdbc.Driver");
                return DriverManager.getConnection(url, username, password);
            } catch (SQLException | ClassNotFoundException e) {
                e.printStackTrace();
            }
    
            return null;
        }
    

提交回复
热议问题