0

I have a problem when I enter data from the application to mysql database, it appears in the form of "????" However, when I enter data via "phpmyadmin" the data appears normally well the problem is when i enter data via application , not related with database any way i tried to change the encode of database and the table and the fields inside the tables

here the insert query in my application

 public static void dbConnect() {
        try{
        Class.forName(DRIVER);
        connector = DriverManager.getConnection(DATA_BASE_BATH, "root", "");
        insert = connector.prepareStatement("INSERT INTO students VALUES (?,?,?,?)");

        }
public static void insert(int id , String name , String special , double gpa){
        dbConnect();
        try{
        insert.setInt(1, id);
        insert.setString(2, name);
        insert.setString(3,special);
        insert.setDouble(4,gpa);
        insert.execute();
        }
        catch(SQLException e){
            System.out.println(e.getMessage());
        }
    }

here the image to understand the problem

database image -the first row is the data entry from the application -and the second row is the data entry manually from the phpmyadmin

0

1 Answer 1

0

Your application isn't properly handling the data.

You need to set the charset during the connection to the MySQL server.

Perhaps by running the command SET NAMES 'UTF8'; as part of your connection script.

This answer states that you can even make it part the JDBC connection string in DATA_BASE_BATH when referenced in your getConnection() function call, as does this one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.