mysql jdbc安装和使用_java – 如何安装JDBC以及如何使用它连接到mysql?

我正在尝试安装JDBC,但我不知道如何,当你只有jar文件时,我将它复制到我的

java ext文件夹,但它一直给我一个错误,谁能告诉我如何完成安装驱动程序并使用它?

下面是我使用的代码

import java.sql.*;

public class Test1

{

public static void main (String[] args)

{

String url = "jdbc:mysql://localhost:3306/sabayafr_sabmah";

String username = "root";

String password = "ma";

Connection connection = null;

try {

System.out.println("Connecting database...");

connection = DriverManager.getConnection(url, username, password);

System.out.println("Database connected!");

} catch (SQLException e) {

System.err.println("Cannot connect the database!");

e.printStackTrace();

} finally {

System.out.println("Closing the connection.");

if (connection != null) try { connection.close(); } catch (SQLException ignore) {}

}

}

}

以下是我得到的回应

Cannot connect to database server

更新#3

C:\Users\AlAsad\Desktop>java -cp .;mysql-connector-java-5.0.8-bin.jar Test1

Connecting database...

Cannot connect the database!

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/

sabayafr_sabmah

at java.sql.DriverManager.getConnection(Unknown Source)

at java.sql.DriverManager.getConnection(Unknown Source)

at Test1.main(Test1.java:12)

Closing the connection.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值