【问题标题】:JDBC Greek charactersJDBC 希腊字符
【发布时间】:2016-04-02 12:24:12
【问题描述】:

在将包含希腊字符的记录插入数据库时​​遇到问题。即使数据库默认字符集是 utf8 并且我还在我得到的连接 URL 中添加了参数?????字符而不是实际的希腊字符。

public class Queries 
{
    private static final String URL = "jdbc:mysql://localhost/Ezazel";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "root";

    private Connection connection = null;
    private PreparedStatement insertSight = null;
    private PreparedStatement insertHotel = null;
public Queries()
    {
        try 
        {
            connection = DriverManager.getConnection( URL,USERNAME, PASSWORD );         
            insertSight = connection.prepareStatement( "INSERT INTO Sights ( Title, Description, Address, Latitude, Longitude ) VALUES ( ?, ?, ?, ?, ? )" );
            insertHotel = connection.prepareStatement( "INSERT INTO Hotels ( Title, Description, Address, Latitude, Longitude ) VALUES ( ?, ?, ?, ?, ? )" );
        } 
        catch ( SQLException e ) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.exit( 1 );
        }
    }

    public void addSight( String title, String description, String address, double latitude, double longitude )
    {
        try 
        {
            insertSight.setString( 1, title );
            insertSight.setString( 2, description );
            insertSight.setString( 3, address );
            insertSight.setDouble( 4, latitude );
            insertSight.setDouble( 5, longitude );

            insertSight.executeUpdate();        
        } 
        catch ( SQLException e )
        {
            e.printStackTrace();
        }
        finally
        {
            try 
            {
                insertSight.close();
                connection.close();
            } 
            catch ( SQLException e )
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
                System.exit( 1 );
            }   
        }
    }
}

【问题讨论】:

  • 我明白了??????在 phpMyAdmin 中

标签: java mysql jdbc


【解决方案1】:

尝试在连接字符串中指定 utf-8,

private static final String URL = "jdbc:mysql://localhost/Ezazel?characterEncoding=utf8";

还有,你在哪里看到??????人物 ?如果您是这个意思,查看器需要支持 UTF-8。

如果数据以希腊语成功保存,但只有 phpMyAdmin 的可见性问题,请尝试验证排序规则和字符集是否设置为 UTF-8

How to display UTF-8 characters in phpMyAdmin?

【讨论】:

    猜你喜欢
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多