将记录插入包含希腊字符的数据库时,我遇到了问题.即使数据库默认字符集是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 );
}
}
}
}
解决方法:
尝试在连接字符串中指定utf-8,
private static final String URL = "jdbc:MysqL://localhost/Ezazel?characterEncoding=utf8";
另外,你在哪里看到?????人物?如果您愿意,Viewer需要支持UTF-8.
如果数据已成功保存为希腊文但只有PHPMyAdmin的可见性问题,请尝试验证collation和charset是否设置为UTF-8
How to display UTF-8 characters in phpMyAdmin?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。