mysql设置连接编码


public final static Connection getConnection() throws SQLException {
   Connection conn = conns.get();
   if(conn ==null || conn.isClosed()){
      conn = _getConnection();
      if(conn == null)
         throw new SQLException("Unabled to get connection.");
      conns.set(conn);
      RequestContext ctx = RequestContext.get();
      conn_context.put(Thread.currentThread().getId(), new ConnectionContext(
            new Exception(),
            (ctx!=null)?ctx.ip():null,
            (ctx!=null)?ctx.uri():null,
            (ctx!=null)?ctx.request().getParameterMap():null)
      );
      conn.prepareStatement("set NAMES utf8mb4").execute();
   }
   return (show_sql && !Proxy.isProxyClass(conn.getClass()))?new _DebugConnection(conn).getConnection():conn;
}


set names utf8mb4
 

0
0

暂无评论