0

我已经在整个互联网上搜索过这个问题......我是 JDBC 的初学者,但这里和其他网站提供的解决方案对我不起作用。

mysql-connector-java-5.1.18-bin.jar在 Linux Mint 32 位上使用“”。我正在使用 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();
        }

    }

}

提前致谢 :)

4

2 回答 2

1

您的连接字符串应该是:

String connectionURL = "jdbc:mysql://localhost:8080/kholofedb";
于 2013-04-05T09:53:34.553 回答
1

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

于 2013-04-05T09:54:01.773 回答