【发布时间】: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 中