Reading Greek text from jdbc / SQL Server 2005 and displaying it using servlet

Okay, the subject says everything, but I'll explain a little further.

I have a database on MS SQL 2005 server that contains Greek text. I've created a servlet that connects to this database using net.sourceforge.jtds.jdbc.Driver

and receives some data with the following commands:

Connection con = DriverManager.getConnection(connectionUrl);
Statement sta = con.createStatement(); 
ResultSet res = sta.executeQuery("SELECT * FROM data");

      

After that I want to use output.println

to display data on the page. As a result, Greek characters appear as question marks (?). I tried to change the browser encoding encoding but no luck so the problem must be on the page. I also tried to display

new String( res.getBytes("text"), "ISO-8859-7");

      

instead res.getString("text")

, with different encodings (UTF-8, UTF-16), but still no luck!

What can I do to see Greek characters?

+2


a source to share


2 answers


The problem can be in several places. Check them all:



  • database encoding
  • connection encoding
  • response encoding ( response.setCharacterEncoding("utf-8")

    )
+1


a source


You need to set the response encoding to UTF-8

. Since you usually use JSPs to display data, you can do this by placing the following line at the top of the JSP page:

<%@ page pageEncoding="UTF-8" %>

      



Also see this article for more reference information and all other aspects you need to consider, as well as for Java EE WebApplication.

+1


a source







All Articles