将记录插入包含希腊字符的数据库时出现问题。即使数据库默认字符集是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 );
}
}
}
}
答案 0 :(得分:2)
尝试在连接字符串中指定utf-8,
private static final String URL = "jdbc:mysql://localhost/Ezazel?characterEncoding=utf8";
另外,你在哪里看到?????人物?如果您愿意,Viewer需要支持UTF-8。
如果数据已成功保存为希腊文但只有phpMyAdmin的可见性问题,请尝试验证排序规则和字符集是否设置为UTF-8