为什么控制台我输出乱码!!!!怎么解决
import java.sql.*;
public class TestMysql {
public static void main(String[] args) throws Exception {
Connection conn = null;
Statement stmt = null;
ResultSet result = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/?characterEncoding =utf8";
conn = DriverManager.getConnection(url, "root", "root");
stmt = conn.createStatement();
String creatDB = "CREATE DATABASE IF NOT EXISTS mydb DEFAULT CHARACTER SET=utf8";
stmt.execute(creatDB);
String droptable = "DROP TABLE IF EXISTS mydb.t_books";
String creatTable = "CREATE TABLE mydb.t_books(id int unsigned NOT NULL,"
+ "name varchar(50) NOT NULL,isbn varchar(20) NOT NULL,price int unsigned,"
+ "PRIMARY KEY(id)) ENGINE=InnoDB DEFAULT CHARSET utf8";
String inserData1 = "INSERT INTO mydb.t_books(id,name,isbn,price) values (1,'刚回家回家','677687',65)";
String inserData2 = "INSERT INTO mydb.t_books(id,name,isbn,price) values (2,'好','7687',45)";
stmt.execute(droptable);
stmt.execute(creatTable);
stmt.execute(inserData1);
stmt.execute(inserData2);
String select = "SELECT * FROM mydb.t_books";
result = stmt.executeQuery(select);
while (result.next()) {
System.out.print(result.getString("id") + " ");
System.out.print(result.getString("name")+ " ");
System.out.print(result.getString("isbn") + " ");
System.out.println(result.getString("price") + " ");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if(result != null) {
result.close();
result = null;
}
if(result != null) {
stmt.close();
stmt = null;
}
if(result != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}