上午9点~中午12点
看视频,学习javafx,复习回顾JDBC与MySQL操作
下午3点~5点30
写项目,试着尝试制作主界面,将服务器端与数据库相连,并对数据库进行预先建表,途中踩坑太多,效率低下
public class ConnMySql {
private Connection conn = null;
private PreparedStatement pps = null;
private String driver = "com.mysql.cj.jdbc.Driver";
private String url = "jdbc:mysql://127.0.0.1:3306/db1?useSSL=false&serverTimezone=UTC";
private String username = "root";
private String password = "ttddww20021208";
public void Open() throws ClassNotFoundException {
try {
//注册驱动
Class.forName(driver);
//获取连接
conn = DriverManager.getConnection(url, username, password);
/*if (conn != null) {
System.out.println("数据库连接成功!");
} else System.out.println("数据库连接失败!");
*/
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
//修改
//查询
}
new ConnMySql().Open();
晚上7点~9点30
写项目,实现雪花算法,和注册或找回密码发送验证码(通过QQ邮箱进行发送随机产生的6位数验证码)
package Server;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import java.util.Random;
public class VerifyCode {
/**
* 发送邮箱验证码工具
*/
//发送邮件
public static void sendMail(String to, String code) throws EmailException {
//创建一个HtmlEmail实例对象
HtmlEmail email = new HtmlEmail();
//邮箱的SMTP服务器
email.setHostName("smtp.qq.com");
//设置发送的字符集
email.setCharset("utf-8");
//开启SSL加密
//email.setSSLOnConnect(true);
//设置发件人的邮箱和用户名
email.setFrom("2557009697@qq.com", "MyChatRoom", "utf-8");
//设置收件人
email.addTo(to, "utf-8");
//设置发件人的邮箱和授权码
email.setAuthentication("2557009697@qq.com", "smqhkfidnfokecia");
//设置发送主题
email.setSubject("验证消息");
//设置发送内容
email.setMsg(code);
email.send();
}
//生成6位数验证码
public static String getVerifyCode(){
Random random = new Random();
String code = "";
for(int i=1;i<=6;i++){
int num = random.nextInt(10);
code += (String.valueOf(num));
}
return code;
}
public static void main(String[] args) throws EmailException {
String id = "2557009697@qq.com";
String code = VerifyCode.getVerifyCode();
VerifyCode.sendMail(id, code);
System.out.println("code:" + code);
}
}
晚上9点30~10点
每日总结