package com.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class Test10_utf8mb4_3 { static String host = "localhost"; static String port = "3306"; static String database = "test"; static String login = "root"; static String password = "root"; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String str = "Сарнаут✔𝐖✪𝐅✔М"; callsql(str); } static public int callsql(String str) { PreparedStatement prstmt = null; ResultSet rs = null; Connection cn = null; try { cn = getConn(); // prstmt = cn.prepareStatement("SET NAMES utf8mb4;"); // prstmt.execute(); // prstmt = cn.prepareStatement("SET CHARACTER SET utf8mb4;"); // prstmt.execute(); // prstmt = cn.prepareStatement("SET CHARSET utf8mb4;"); // prstmt.execute(); prstmt = cn.prepareStatement("show variables like 'character%';"); System.out.println(prstmt.toString()); prstmt.execute(); rs = prstmt.getResultSet(); while(rs.next()){ System.out.println(rs.getString(1)+" "+rs.getString(2)); } prstmt = cn.prepareStatement("call test.testRecord(?);"); prstmt.setString(1, str); System.out.println(prstmt.toString()); prstmt.execute(); rs = prstmt.getResultSet(); while(rs.next()){ System.out.println(rs.getString(1)); } // new RunThread2( // gmjp.n[i].id, // Addresses.makeUrl(Addresses.SEGMENT_SERVER_ADDRESSES[gmjp.n[i].segmentId]), // Addresses.HOST_ADDRESSES[gmjp.n[i].segmentId], referer, // authKey, userID, version); // Thread.sleep(2000L); } catch (Exception e) { //System.out.println(prstmt.toString()); System.err.println(prstmt.toString()); e.printStackTrace(); return -1; } finally { close(cn); } return 0; } static private Connection getConn() throws ClassNotFoundException, InterruptedException { //Thread.sleep(2L); Class.forName("com.mysql.jdbc.Driver"); Connection c = null; try { c = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, login, password); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return c; } static private void close(Connection _c){ if(_c!=null) try { _c.close(); } catch (SQLException e) { e.printStackTrace(); } } }