T
T
The_XXI2021-04-09 15:49:48
MySQL
The_XXI, 2021-04-09 15:49:48

Why is nothing displayed when querying the database if a search is made by value from "Russian" letters?

I make a query to the database on the name column, and if the name consists of English. letters, then everything is displayed. If name consists of Russian. letters, then nothing comes:
60704d00b6b98612896442.jpeg
The first few lines from the database:
60704bc3e4da7383511290.jpeg
Request and output code:

ResultSet resultSetManufacturerID = DBHandler.executeQuery("SELECT ID FROM manufacturer WHERE Name = '"+ManufacturerTitle+"'");
                String manufacturerID = null;
                try {
                    while (resultSetManufacturerID.next()) {
                        manufacturerID = resultSetManufacturerID.getString(1);

                    }
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
System.out.println("manufacturerID: " + manufacturerID);

executeQuery code:
public static ResultSet executeQuery(String sql) {
        ResultSet resultSet = null;
        System.out.println(sql);
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            if (sql.contains("SELECT")) {
                resultSet = preparedStatement.executeQuery();

            } else {
                preparedStatement.executeUpdate();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return resultSet;
    }

What could be the problem?
If I copy the request and paste it into the workbench, then everything works, the ID is displayed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-04-09
@sergey-gornostaev

First, you should not use string concatenation to form sql queries. Secondly, you should make sure that the string encoding matches the database encoding.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question