11.14
数据库的全文搜索功能
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class JavaMySQLFullTextSearchExample {
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("SELECT * FROM my_text_table WHERE MATCH(text_column) AGAINST('search_keyword' IN NATURAL LANGUAGE MODE)");
while (rs.next()) {
// 处理结果
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}