【问题标题】:No suitable driver found for dbc:mysql://localhost:8080/kholofedb找不到适合 jdbc:mysql://localhost:8080/kholofedb 的驱动程序
【发布时间】:2013-04-05 09:51:30
【问题描述】:

我整个昨天都在互联网上搜索过这个问题......我是 JDBC 的初学者,但这里提供的解决方案和其他网站不适合我。

我在 Linux Mint 32 位上使用“mysql-connector-java-5.1.18-bin.jar”。我使用的是 Eclipse 3.8 ...我已经安装了 mySQL-server 并且它正在运行(我使用:sudo service mysql start 运行它)...在运行时出现此错误

connecting to psysical database...


java.sql.SQLException: No suitable driver found for dbc:mysql://localhost:8080/kholofedb
  at java.sql.DriverManager.getConnection(DriverManager.java:604)
  at java.sql.DriverManager.getConnection(DriverManager.java:221)
  at com.psybergate.database.SimbleCode.main(SimbleCode.java:21)

这是我的源代码:

package com.psybergate.database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class SimbleCode 
{

    private static final String USER = "root" , PASS = "";


    public static void main(String ...args)
    {
        try {
            String connectionURL =       "dbc:mysql://localhost:8080/kholofedb";
               Class.forName("com.mysql.jdbc.Driver");
        //  Class.forName("org.postgresql.Driver");
            System.out.println("connecting to psysical database...");
            Connection conn = DriverManager.getConnection(connectionURL  , USER , PASS);

            Statement statement = conn.createStatement();
            System.out.println("Connection has been made");

            Scanner keyBoardScanner =  new Scanner(System.in);
            System.out.println("Enter table name:");
            String tableName = keyBoardScanner.nextLine();

            System.out.println("Creating table...");
            statement.executeQuery("create table " + tableName + " (name , age ,salary)");
            System.out.println("Table successfully created");
            System.out.println("Inserting data into the table ...");
            statement.executeUpdate("insert into " + tableName + "values (kholofelo , 21 , 9969696)");
        }
        catch (ClassNotFoundException | SQLException e) {

            e.printStackTrace();
        }

    }

}

提前致谢:)

【问题讨论】:

    标签: java mysql sql jdbc mysql-connector


    【解决方案1】:

    您的连接 URL 应该以“jdbc:”而不是“dbc:”开头

    【讨论】:

    • ` 通信链路故障 最后一个成功发送到服务器的数据包是 0 毫秒前。驱动程序没有收到来自服务器的任何数据包。在 sun.reflect.NativeConstructorAccessorImpl.newInstance0`
    【解决方案2】:

    你的连接字符串应该是:

    String connectionURL = "jdbc:mysql://localhost:8080/kholofedb";
    

    【讨论】:

    • 现在我解决了这个问题,但是我遇到了另一个异常,我在使用 postgresql 时也遇到了这个异常
    • 什么异常?请检查您的端口是 8080 还是 3306。
    • 修复后出现此异常:通信链路故障最后一个成功发送到服务器的数据包是 0 毫秒前。驱动程序没有收到来自服务器的任何数据包。在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 java.lang.reflect.Constructor .newInstance(Constructor.java:525) 在 com.mysql.jdbc.Util.handleNewInstance(Util.java.
    • mysql的默认端口是3306。或许试试这个比较好:String connectionURL = "jdbc:mysql://localhost:3306/kholofedb";
    猜你喜欢
    • 2014-08-05
    • 2018-12-13
    • 2019-10-16
    • 2016-10-01
    • 2012-05-08
    • 2017-08-26
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多