总结
到今天为止,学习了java基础,数据库基础,JDBC从数据库对一张表进行增删改查
用Jdbc对一张表进行增删改查
首先创建一个JDBCComon
public class JDBCComon {
public Connection getConnection() throws ClassNotFoundException, SQLException{
Class.forName("com.mysql.cj.jdbc.Driver");
//java10是数据库的名字
String url="jdbc:mysql://localhost:3306/java10?useSSL=false&serverTimezone=UTC";
//登录数据库用户名
String username="root";
//登录数据库密码
String pwd="Java20190713*yy";
Connection conn = DriverManager.getConnection(url,username,pwd);
return conn;
}
然后创建相应的数据库类型
package com.base.day8;
public class Student {
private String name;
private double score;
private int id;
private String subject;
private int team_id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public int getTeam_id() {
return team_id;
}
public void setTeam_id(int team_id) {
this.team_id = team_id;
}
}