2024年10月23日總結

离璨霂發表於2024-10-23

今天繼續學習了資料庫的連線,這是今日總結完成的模版(還有一些地方有問題)
package mapper;

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

public class studentsystemmapper {
Connection conn=null;
public studentsystemmapper() throws Exception {
Class.forName("com.mysql.cj.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/studentsystem";
String user="root";
String password="qq15613935170";
conn=DriverManager.getConnection(url,user,password);
String sql="update studentsystem set name=?,age=? where id=?";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1,name);
ps.setInt(2,age);
ps.setInt(3,id);
System.out.println(ps.executeUpdate());
}
}