1. SQL查询语言:
SELECT * FROM TABLE_NAME;
INSERT INTO TABLE_NAME (column1, column2, …) VALUES (value1, value2, …);
UPDATE TABLE_NAME SET column1=value1, column2=value2, …;
DELETE FROM TABLE_NAME WHERE condition;
2. 存储过程:
CREATE PROCEDURE procedure_name
[IN|OUT|INOUT] parameter_name data_type
BEGIN
statements
END;
3. 触发器:
CREATE TRIGGER trigger_name
BEFORE INSERT OR UPDATE
ON table_name
FOR EACH ROW
BEGIN
statements
END;
4. JDBC编程:
Connection conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
// TODO: 处理每一行数据
}
5. ORM(对象关系映射):
@Entity
public class Blog {
@Id
private Long id;
@Column
private String title;
@Column
private String content;
}
以上是MySQL编程中常见的几种方式。不同的场景需要使用不同的方式,大家需要灵活掌握。同时,也可以结合多种方式来完成一个复杂的任务。