// Java代码示例:添加新教材
public class TextbookManager {
public void addTextbook(String title, String author, int quantity) {
// 连接数据库
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/textbooks", "username", "password");
String sql = "INSERT INTO textbooks (title, author, quantity) VALUES (?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, title);
pstmt.setString(2, author);
pstmt.setInt(3, quantity);
pstmt.executeUpdate();
conn.close();
}
}
]]>