I have problems when inserting a record into the database that includes greek characters.Even though the database default characters set is utf8 and I also added the parameters in the connection URL I get ????? characters instead of the actual greek characters.
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 );
}
}
}
}