import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;


public class Test {

	
	public static void main(String[] args) {
		try {
			
			String driver = "com.mysql.jdbc.Driver";
			String url = "jdbc:mysql://localhost/test?characterEncoding=UTF-8&useUnicode=true&user=USER&password=XXXXX";

			Class.forName(driver).newInstance();
			Connection conn = DriverManager.getConnection(url);

			// DDL: create table test (id INT AUTO_INCREMENT PRIMARY KEY, text TEXT);
			
			PreparedStatement ps = conn
					.prepareStatement("INSERT INTO test (text) VALUES (?)");

			// the deadly sequence   \xF4\x80\x81\xBA
			byte[] bytes = {(byte)0xF4, (byte)0x80, (byte)0x81, (byte)0xBA };
			
			String str = new String(bytes, "utf-8");			
	
			try {
				ps.setString(1, str);
				ps.execute();
			}finally {
				ps.close();
				conn.close();
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
}
