学习了如何在 Java 中执行复杂的多表连接查询
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class JavaMySQLMultiTableJoinExample {
public static void main(String[] args) {
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase", "username", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT t1.column1, t2.column2 FROM table1 t1 JOIN table2 t2 ON t1.id = t2.table1_id");
while (rs.next()) {
System.out.println(rs.getString("column1") + " " + rs.getString("column2"));
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}