Boa tarde galera,
Obs.: Já li tópicos parecidos, mas nenhum solucionou meu problema!
Tenho uma tabela no mySQL (innoDB) que contém alguns registros, esses registros possuem ?ão?, ?ç?, e outros caracteres especiais. Quando faço um SELECT no banco, aparece todos os registros configurados certinho com os acentos e tal, masssssss daí faço o seguinte no JAVA e as palavras vem com os acentos todos desnconfigurados:
public static String[] getNomesGrupos() throws Exception {
try{
conexao = ConexaoDB.getCon();
conexao.setAutoCommit(false);
statement = conexao.prepareStatement("SELECT * FROM grupoUsuarios");
ResultSet result = statement.executeQuery();
List<String> obj = new ArrayList<String>();
while(result.next()){
obj.add(result.getString(1));
}
String[] obj2 = new String[obj.size()+1];
obj2[0] = "--";
for(int i=1; i<obj2.length; i++)
obj2[i] = obj.get(i-1);
return obj2;
}
catch(Exception ex){
try {
conexao.rollback();
} catch (SQLException e) {
throw new Exception(ex);
}
throw new Exception(ex);
}
finally{
try{
conexao.setAutoCommit(true);
statement.close();
conexao.close();
}
catch(Exception ex){
throw new Exception(ex);
}
}
}
Classe de conexão:
public class ConexaoDB {
private static Connection conexao;
// Método retorna uma nova conexão com o gerenciador mySQL
public static Connection getCon() throws Exception {
try {
if (conexao == null || conexao.isClosed()) {
Class.forName("com.mysql.jdbc.Driver");
conexao = DriverManager.getConnection("jdbc:mysql://localhost/ems","root", "");
}
}
catch (Exception ex) {
throw new Exception(ex);
}
return conexao;
}
}
O pior é que faço o mesma estrutura de SELECT pra outras consultas em outras tabelas e os dados vêm certo, menos nesta. Por quê?
===========================
EU ESTAVA FAZENDO O INSERT PELO BANCO E CONSULTADO, DAÍ DAVA ESSE PROBLEMA.
MUDEI O INSERT PARA SER FEITO PELO JAVA, DAÍ RESOLVEU, Oo.