Accentuation problems in sql

Asked

Viewed 154 times

0

I have problems accentuating the registration. If I register names with accent, they leave confused, I do not know if it is some sql problem. I already changed the utf8 for this but the text of the site gets confused.

<%@ 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>
  • Try: <%=out.println(rs.getString("bai_codigo")) %> ; <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> and <%@pagelanguage="java" contenttype="text/html;UTF-8" pageEncoding="UTF-8" %>

  • adds this <meta http-equiv="Content-Type" content="text/html; charset='UTF-8'>

  • I couldn’t, from the mistake

2 answers

0

I tried this way jdbc:postgresql://" + hostname + "/" + Database + "? charset=LATIN1" that would be so Connection con = Drivermanager.getConnection(jdbc:postgresql://" + localhost/js + "/" + Database + "?ENCODING=LATIN1"); Was a mistake

0

Clarifies a doubt. Are you saving the data and in the database was saved with the sharp character broken? Or when you upload the information from the bank to the HTML, is it broken? If you want to save data accentuated, I recommend creating the connection as follows:

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

Remembering that the Encode UTF-8 has no accentuation

  • I believe you haven’t read my answer and you don’t understand his problem either. It is with accentuation problem, creating a connection to the database without specifying the charset used by the database. Creating the connection using "jdbc:postgresql://hostname+Database + ? charset=LATIN1" solves its problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.