1. Recently, because of writing the Java EE version of the bookstore management system, encountered the problem of fuzzy query, because I query the keyword is Chinese, resulting in the beginning of a lot of problems, ResultSet rs-> such as: SELECT * from the book Where bookname = ' Operating system '; This statement can be found in the MySQL database, but Rs.next () is always not false; it is strange that the only reason I can think of is the Chinese garbled problem;
Is the format you want to encode when you write the URL:---. URL = "Jdbc:mysql://localhost:3306/bookshopping?characterencoding=utf8"; This URL is ct = drivermanager.getconnection (URL, USER, PASSWORD); I believe I don't have to say more. In this way, the Chinese query statement can be used normally;
2. Solve the problem of fuzzy query;
The fuzzy query statement is generally:select * from the book where the BookName like '% operating system% '; But if this is true, it is absolutely not found, and will error (the content of the specific error I do not explain); then the solution is: Use a wildcard character?
SELECT * from book where bookname?;
Then use the SetString method of preparestatement;
Like what:
String str = "operating system";
Ps.setstring (1, "%" +str + "%"); it's going to work out.
JDBC Fuzzy query and preparestatement Chinese garbled solution