我昨天一直在互联网上搜索这个问题...我是 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();
}
}
}
提前致谢:)
最佳答案
您的连接 URL 应以“jdbc:”开头,而不是“dbc:”
关于java - 没有找到适合 dbc :mysql://localhost:8080/kholofedb 的驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15830835/