java - Encoding problems in database -
i have postgres 9.2 database, encoding utf-8. have application(written in java) update database, reading .sql files , executing them in database. found problem: in 1 of .sql files, have following instruction:
insert usuario(nome) values('usuário padrão');
after executing this, when go table data, inserted this: "usuário padrão"
if execute command directly pgadmin, creates correctly. don't know if it's problem in database, or in program executes scripts.
---edit---
here how jdbc connection:
public static connection getconnection() throws sqlexception{ connection connection; string url="jdbc:postgresql://"+servidor+":"+porta+"/"+nomebanco; properties props = new properties(); props.put("user", usuario); props.put("password", senha); connection=drivermanager.getconnection(url,props); connection.setautocommit(false); return connection; }
and here code use read file, looks correct, because if print string read file, shows correct string.
public static string lerarquivo(file arquivo){ stringbuilder conteudo=new stringbuilder(); bufferedreader br = null; try { br=new bufferedreader(new filereader(arquivo)); string linha; while((linha=br.readline())!=null){ conteudo.append(linha).append("\n"); } } catch (ioexception e) { frameerrobasico f=new frameerrobasico(null, true); f.settext("erro ao ler arquivo.",e); f.setvisible(true); }finally{ try{br.close();}catch(exception e){} } return conteudo.tostring(); }
this problematic line:
br=new bufferedreader(new inputstreamreader(new fileinputstream(arquivo), "utf-8"));
(looks crystal ball still working well!)
Comments
Post a Comment