Accentuation problems in sql

0

I have problems with accentuation in the registry. If I register names with an accent, they come out confused, I do not know if it's any sql problem. I've already changed utf8 to this but the site text gets confusing.

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link rel="stylesheet" type="text/css" href="cadastro_costumização.css"/>
<title>Untitled Document</title>
<style type="text/css">
<!--
body,td,th {
    font-family: Times New Roman, Times, serif;
    font-size: 16px;
    color: #000;
}
h1{
    color:#00F;
    font-family:Georgia, "Times New Roman", Times, serif;
    font-size:24px;

}
p{
    color:#003
    font-family:Georgia, "Times New Roman", Times, serif;
    font-size:22px;

}
table{
    background-color: #69F;
}
-->
</style></head>

<body>

<p align="center">Manunten&ccedil;&atilde;o do Bairro</p>
<p align="center"><img src="img/loja.png" width="290" height="158" /></p>
<a href="#" onclick="window.open('imprime_usuario.jsp')">impress&atilde;o na tela cheia</a>
<div align="center"></br> <p>Cadastre e Impresse
aqui</p>
  <a href="bairro_cadastro.jsp"><img src="img/cadstrar.png" width="82" height="83" /></a><a href="imprime_usuario.jsp"><img src="img/indice.jpg" width="82" height="83" /></a>
<h1><strong>Ordena&ccedil;&atilde;o: <a href="bairro.jsp?ordenacao=crescente">Crescente</a>- <a href="bairro.jsp?ordenacao=alfabetica">Alfab&eacute;tica</a></strong></h1></div>
<div align="center" > 
  <table width="777" border="0">
    <tr>
      <td width="150"><div align="center"><p>C&oacute;digo</p></div></td>
      <td width="251"><div align="center">
        <p>Nome do bairro</p></div></td>

      <td width="254"><div align="center"><p>Alterar</p></div></td>
      <td width="104"><div align="center"><p>Excluir</p></div></td>
    </tr>

     <% 

try
{
Class.forName("org.postgresql.Driver");
    //out.println("Conceguiu carregar o drive<br>");
    Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/js","postgres","1974");
    //out.println("Conexão com sucesso");

    Statement st = con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    //out.println("passou pelo Statement ");
    if(request.getParameter("acao")!= null)
    {
    st.executeUpdate("delete from bairro where bai_codigo="+request.getParameter("codigo"));
    }
    ResultSet rs = null;

    if(request.getParameter("ordenacao")== null)
    {
         rs = st.executeQuery("select * from bairro order by bai_nome ");
    }

    else if(request.getParameter("ordenacao").equals("crescente"))
    {
    rs = st.executeQuery("select * from bairro ");  
    }

    else if(request.getParameter("ordenacao").equals("alfabetica"))
    {
    rs = st.executeQuery( "select * from bairro order by bai_nome");    
    }

    while(rs.next())
    { %>

    <tr>
      <td><div align="center"><%=rs.getString("bai_codigo")  %></div>
      </td>
      <td><div align="center"> <%=rs.getString("bai_nome")  %></div></td>

      <td><div align="center">
        <form id="form1" name="form1" method="post" action="">
          <a href="bairro_altera.jsp?codigo=<%=rs.getString ("bai_codigo")%>&amp;bairro=<%=rs.getString("bai_nome")%>"><img src="img/POWER - SWITCH USER.png" width="30" height="30" /></a>
        </form>
      </div></td>
      <td><div align="center"><a href="bairro.jsp?acao=excluir&amp;codigo=<%=rs.getString("bai_codigo")%>"><img src="img/Lixeiras_1545_Poubelle_v3.png" width="30" height="30" /></a></div></td>
    </tr>

  <%   }
}
catch(ClassNotFoundException erroClass)
{
    out.println("Driver não localizado,erro="+ erroClass); 
    }
catch(SQLException erroSQL)
{
out.println("Erro de conexão com o Banco de dados,erro="+ erroSQL); 
}

%>

  </table> 
</div>
</body>
</html>
    
asked by anonymous 08.11.2017 / 16:34

2 answers

0

Clarify a doubt. Are you saving the data and the database was saved with the broken accented character? Or when you load the bank information into the HTML, is it broken? If you want to save data with accent, I recommend creating the connection as follows:

jdbc:postgresql://" + hostName + "/" + dataBase + "?charSet=LATIN1"

Remembering that encode UTF-8 does not have an accent

    
09.11.2017 / 18:08
0

I tried this way jdbc: postgresql: // "+ hostName +" / "+ dataBase +"? charSet = LATIN1 " that would be this way Connection with = DriverManager.getConnection (jdbc: postgresql: // "+ localhost / js +" / "+ dataBase +"? ENCODING = LATIN1 "); Gave error

    
17.11.2017 / 00:02