3.9总结

关于使用Android studio连接MySQL数据库:

1,需要下载MySQL connector/J驱动程序;

2,将驱动添加到Android studio中(类似于eclipse连接MySQL的步骤);

3,创建表(连接数据库必须步骤-首先创建一个表);

4,进行连接,相关的代码为:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MySQLConnection {
private static final String URL = "jdbc:mysql://localhost:3306/test";
private static final String USER = "root";
private static final String PASSWORD = "123456";

public static Connection getConnection() throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return DriverManager.getConnection(URL, USER, PASSWORD);
}
}

5,执行查询的操作(目前还未成功)。

posted @ 2023-03-09 21:42  迷路的羔羊-  阅读(17)  评论(0)    收藏  举报