Java数据库连接问题

标签 java jdbc

我的代码存在以下问题:

import java.sql.*;

public class App {

    public static void main(String[] args){

        String url = "jdbc:mysql://localhost:3306" ;
        try{ 
            Class.forName("com.mysql.jdbc.Driver"); 
            }
        catch(ClassNotFoundException e) 
                { System.out.println("Eroare incarcare driver!\n" + e);
                return; 
                }
        try{ 
            Connection con = DriverManager.getConnection(url);

        // Golim tabelul persoane 
                String sql = "DELETE FROM persoane"; 
                Statement stmt = con.createStatement(); 
                stmt.executeUpdate(sql);
                stmt.execute("CREATE DATABASE IF NOT EXISTS test");
                stmt.execute("USE test");

我遇到了异常(exception)...知道如何才能完成这项工作吗?谢谢。

enter code here

最佳答案

您需要下载 jdbc 连接器并将其添加到类路径中。

http://dev.mysql.com/downloads/connector/j/

关于Java数据库连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29077337/

相关文章:

java - 哪个接口(interface)的方法在类中实现了

java - 无法加载请求的类: org. hibernate.MySQL5InnoDBDialect

java - 使用 for 循环创建多维数组

java - 从另一个存储过程中的存储过程获取 ResultSet

java - Android Studio JDBC MySQL

Java数据库元数据

java - 在 Selenium Webdriver 中将 DesiredCapability 与 FirefoxOptions 合并会导致 java.lang.NoSuchMethodError

java - java和数据库之间共享常量

java - 准备语句参数问题

java - jTable 行数 VS 模型行数