在intellij中使用JDBC / Mysql Connector [英] Use JDBC/Mysql Connector in intellij idea

查看:219
本文介绍了在intellij中使用JDBC / Mysql Connector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java的新手,我需要与MySQL服务器(本地)建立连接,我已经在Intellij中添加了这些库,但它似乎不起作用,IDE无法找到我认为的类。 ..我变得疯狂我正在寻找两个小时......我来自visual studio / c#dev环境,我认为我应该错过一些东西......



在这里,您可以从我的IDE和我想要使用的简单代码中获取图片。
您还可以推断我已经在我的项目中导入了jar(mysql-jdbc)。




I'm new in Java, and I need to establish a connection to a MySQL server (local), I have add the libraries in Intellij idea but it seems not work, the IDE can't find the class i think... I become crazy I'm searching since two hours... I come from visual studio/c# dev environment and i think that i should miss something...

Here you can have a pic from my IDE and the simple code that I wanted use. You can also deduce that I have import the jar in my project (mysql-jdbc).

IDE pic

Edit : here is the code, the comment show where the error appear :

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
import org.*;
import com.mysql.jdbc.Driver;


public class JdbcLogin {
    public String Login;
    public String MotDePasse;
    private boolean Logged = false;

    public void StartBdd(){
        String driverName = "com.mysql.jdbc.Driver";
        Class.forName(driverName); // here is the ClassNotFoundException

        String serverName = "localhost";
        String mydatabase = "suptodo";
        String url = "jdbc:mysql://" + serverName + "/" + mydatabase;

        String username = "root";
        String password = "azerty";
        Connection connection = DriverManager.getConnection(url, username, password);
    }
}

解决方案

You have to add 'mysql:mysql-connector-java:5.1.40' from maven or add it as java library as shown:

这篇关于在intellij中使用JDBC / Mysql Connector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆