简体   繁体   English

找不到适用于jdbc:mysql / localhost:3306 / world的驱动程序

[英]No suitable driver found for jdbc:mysql/localhost:3306/world

I'm new at this area programming and I got some problems with driver, kinda: 我是该领域编程的新手,我的驱动程序有点问题:

MySql is working fine when I'm using it directly with client, problem is I can't make a connection tomcat with MySql 当我直接与客户端一起使用时,MySql工作正常,问题是我无法与MySql建立连接

I put all my drivers at WEB-INF/lib 我将所有驱动程序放在WEB-INF / lib中

using mysql 5.7, tomcat 9.1, java 8, IntellijIdea 2016.1.1 使用mysql 5.7,tomcat 9.1,java 8,IntellijIdea 2016.1.1

java.sql.SQLException: No suitable driver found for jdbc:mysql/localhost:3306/world at java.sql.DriverManager.getConnection(DriverManager.java:689) at java.sql.DriverManager.getConnection(DriverManager.java:247) at Db.main(Db.java:20) java.sql.SQLException:在java.sql.DriverManager.getConnection(DriverManager.java:247)上的java.sql.DriverManager.getConnection(DriverManager.java:689)上找不到适用于jdbc:mysql / localhost:3306 / world的驱动程序在Db.main(Db.java:20)

so here is my code: 所以这是我的代码:

import java.io.Serializable;

import java.sql.*;

public class Db implements Serializable{


public static void main(String args[]){
    Connection connection;
    final String dbURL = "jdbc:mysql/localhost:3306/world";
    final String username = "root";
    final String pswd = "******";
    try{
        DriverManager.getDrivers();
        connection = DriverManager.getConnection(dbURL,username,pswd);
        Statement statement = connection.createStatement();
        String query = "SELECT * FROM city WHERE Name LIKE 'New%'";
        ResultSet result = statement.executeQuery(query);
        while(result.next()){

            int id          = result.getInt("ID");
            String name     = result.getString("Name");
            String cCode    = result.getString("CountryCode");
            String district = result.getString("District");
            int pop         = result.getInt("Population");

            System.out.print("id = "+id+"</br>Name = "+name+
                    "</br>Code = "+cCode+"</br>District = "+district+
                    "</br>Population = "+pop+"</br>");
        }
    }catch (SQLException e){
        e.printStackTrace();
    }catch(Exception e){
        e.printStackTrace();
    }
}
}

Syntax for MySQL JDBC URL is: MySQL JDBC URL的语法为:

The general format for a JDBC URL for connecting to a MySQL server is as follows, with items in square brackets ([ ]) being optional: 用于连接到MySQL服务器的JDBC URL的一般格式如下,方括号([])中的项目是可选的:

 jdbc:mysql://[host1][:port1][,[host2][:port2]]...[/[database]][?propertyName1=propertyValue1[&propertyName2=propertyValue2]...] 

Here is a simple example for a connection URL: 这是连接URL的简单示例:

 jdbc:mysql://localhost:3306/sakila?profileSQL=true 

Your URL jdbc:mysql/localhost:3306/world is missing a :/ after mysql . 您的网址jdbc:mysql/localhost:3306/worldmysql之后缺少:/

Port number defaults to 3306 , so your URL should be: 端口号默认为3306 ,因此您的URL应为:

jdbc:mysql://localhost/world

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JDBC JAVA找不到适合的驱动程序jdbc:mysql:// localhost:3306 / voting - JDBC JAVA No suitable driver found for jdbc:mysql://localhost:3306/voting 发现此错误“没有找到适合 jdbc:mysql//localhost:3306/student 的驱动程序” - Found this error "No suitable driver found for jdbc:mysql//localhost:3306/student" 如何解决:找不到适合jdbc的驱动:mysql://localhost:3306/sampledb - How to solve: No suitable driver found for jdbc:mysql://localhost:3306/sampledb 错误:找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - ERROR: No suitable driver found for jdbc:mysql://localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / jpa的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/ jpa 找不到适用于jdbc:mysql // localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql//localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/test Eclipse - Hibernate:没有为jdbc找到合适的驱动程序:mysql:// localhost:3306 / hibernatedb - Eclipse - Hibernate : No suitable driver found for jdbc:mysql://localhost:3306/hibernatedb 找不到适用于jdbc:mysql // localhost:3306 / demo的驱动程序吗?useSSL = false - No suitable driver found for jdbc:mysql//localhost:3306/demo?useSSL=false SQLException:找不到适用于jdbc:mysql:// localhost:3306 / dbname的驱动程序 - SQLException: No suitable driver found for jdbc:mysql://localhost:3306/dbname
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM