1.DBUtils.java类//配置dbcp数据源
import org.apache.commons.dbcp2.BasicDataSourceFactory;
import javax.sql.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class DBUtils {
static DataSource ds;
static{
Properties prop = new Properties();
try{
InputStream in = new DBUtils().getClass().getClassLoader().getResourceAsStream("dbcpconfig.properties");
prop.load(in);
ds = BasicDataSourceFactory.createDataSource(prop);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static DataSource getDataSource(){
return ds;
}
}
}
2.dbcpconfig.properties文件
#数据库驱动
driverClassName=com.mysql.jdbc.Driver
#数据库url
url=jdbc:mysql://localhost:3306/甩头udent
#账号密码
username=root
password=123
3.Student.java
public class Student {
private String id;//学号
private String name;//姓名
private String sex;//性别
private String grade;//班级
private String address;//住址
private String tele;//手机号
private String email;//邮箱
public void setName(String name){
this.name = name;
}
public void setId(String id){
this.id =id;
}
public void setSex(String sex){
this.sex = sex;
}
public void setGrade(String grade){
this.grade = grade;
}
public void setAddress(String address){
this.address = address;
}
public void setTele(String tele){
this.tele = tele;
}
public void setEmail(String email){
this.email = email;
}
public String getId(){
return id;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public String getGrade(){