Java Server Pages - 插入MySql时的排序规则? [英] Java Server Pages - collation when inserting into MySql?
问题描述
我正在使用Java Server Pages,并在从我的应用程序插入数据时遇到排序问题。我的插入代码如下所示:
I am using Java Server Pages and got problem with collation when inserting data from my application. My insert code looks like this:
<%@page import="java.sql.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% Class.forName( "com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/myapp", "root", "");
Statement st=con.createStatement();
ResultSet rs;
st.executeUpdate("insert into table values (default,1,2,šđžćč)"); %>
在我的数据库中,结果看起来像š?ž?? (所以他可以看到理解2个字母,但不是全部)。如何修复它以便所有字母都在我的数据库中?
In my database result looks like this š?ž?? (so he can see understand 2 letters but not all). How to fix it so all letters will be in my database?
编辑:
我可以通过phpmyadmin插入这些字符的数据,但我不能从.jsp文件到数据库。这就像我的jsp文件中的charset = utf-8无效。
EDIT : I can insert data with those characters via phpmyadmin, but i can't from .jsp file to database. It's like charset = utf-8 on my jsp file is not working.
推荐答案
从旧路径添加到我的连接时问题解决了
Problem solved with adding to my connection from old path
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/myapp", "root", "");
到
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/myapp?useUnicode=true&characterEncoding=UTF-8", "root", "");
这篇关于Java Server Pages - 插入MySql时的排序规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!