private void openConnection(){
Connection connection = null;
try {
// Load the JDBC driver
// MySQL MM JDBC driver
String driverName = "org.gjt.mm.mysql.Driver";
Class.forName(driverName);
// Create a connection to the database
String serverName = "localhost";
String mydatabase = "mydb";
// a JDBC url
String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
url += "?useUnicode=true&characterEncoding=UTF-8";
String username = "root";
String password = "rootpassword";
connection = DriverManager.getConnection(url, username, password);
stmt = connection.createStatement();
} catch (ClassNotFoundException e) {
System.out.print("Can't Find JDBC Driver for connect Database");
} catch (SQLException e) {
System.out.print("Can't Connect Database");
}
}
//@End Method openConection()จุดสำคัญจริงๆ คงอยู่ตรง
url += "?useUnicode=true&characterEncoding=UTF-8";
นี่แหล่ะนะ
