11.12

优化数据库索引
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class IndexOptimizationExample {
public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase", "username", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("EXPLAIN SELECT * FROM my_table WHERE indexed_column = 'value';");
while (rs.next()) {
System.out.println(rs.getString(1) + " " + rs.getString(2));
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

posted @ 2024-11-12 22:59  霸王鸡  阅读(0)  评论(0编辑  收藏  举报