Chinese characters are not printed when connecting to sql from java


I'm doing a function that all it does is print all the values of a field in a table, however I have Chinese letters saved in the database, and from sql server they look good, but when printed in java it shows only question marks, this is my function:

public void imprimir() {
    try {
        Connection connection = DriverManager.getConnection("jdbc:sqlserver://;databaseName=foo;characterEncoding=UTF‑8",
                "usuario", "password");
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT * FROM TABLA");

        while (
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Connect.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(Connect.class.getName()).log(Level.SEVERE, null, ex);

asked by gibran alexis moreno zuñiga 30.01.2018 в 21:32

2 answers


One possibility is that you are not saving the character as unicode in the database. For this you need to use the data type nvarchar instead of varchar .

answered by 30.01.2018 / 21:59

You must specify the encoding to UTF-8

Try the following

PrintStream out = new PrintStream(System.out, true, "UTF-8");

Or set in the ide the text file encoding in UTF-8

answered by 30.01.2018 в 21:56