音乐管理系统
1.建立好相应目录和文件夹
2.连接数据库
public static Connection getConnection() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/zjgm?user=root&password=xiayin0001&characterEncoding=utf-8&useSSL=true");
return connection;
}
3.放入数据
在数据库里建立所需要的表并写入初始数据
4.完成代码
1.Dbutil类
package com.zhongruan.util;
import java.sql.*;
public class Dbutil {
public static Connection getConnection() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/zjgm?user=root&password=xiayin0001&characterEncoding=utf-8&useSSL=true");
return connection;
}
public static void Closeall(ResultSet resultSet, Statement statement, Connection connection){
if (resultSet!=null){
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (statement!=null){
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
2.Music类
package com.zhongruan.music;
public class Music {
private int id;
private String name;
private String author;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.autho