intellij mysql jdbc_在intellij中使用JDBC / Mysql Connector

bd96500e110b49cbb3cd949968f18be7.png

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).

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:

2d76u.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值