Data retrieval in unicode is not working in Java as well as PHP.

8 views
Skip to first unread message

ravi

unread,
Nov 27, 2009, 12:40:55 PM11/27/09
to Free Tamil Computing(FTC)
---------- Forwarded message ----------
From: பேரா முத்து <aru.mut...@gmail.com>
Date: 2009/11/27
Subject: Data retrieval in unicode is not working in Java as well as
PHP.
To: தமிழ்க் கணிமைத் திட்டங்கள்
<tamilcomput...@googlegroups.com>



Please let me know how to retrieve unicode data using either Java or
PHP. I tried using character set setting to utf 8 , but still I am
unable to get the result. What I am getting is ???? as a result.

Source code is as below.

/*
JAVA FILE
*/


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.lang.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
*
* @author Administrator
*/
public class NewServlet extends HttpServlet {

static Connection con;
static Statement stt;
static ResultSet rs;

/**
* Processes requests for both HTTP <code>GET</code> and
<code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.util.Properties prop = new java.util.Properties();
prop.put("charSet", "UTF-8");
//prop.put("user", username);
// prop.put("password", password);
con = DriverManager.getConnection("jdbc:odbc:MSAccessDatabase", prop);

//con=DriverManager.getConnection
("jdbc:odbc:MSAccessDatabase");
stt=con.createStatement();
rs=stt.executeQuery("select Tamil from mytab");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet NewServlet at" + " ????, ????? "
+ request.getContextPath () + "</h1>");
while(rs.next())
{
out.println(rs.getUnicodeStream("Tamil"));
}
} catch (Exception e) {System.out.println(e);};
out.println("</body>");
out.println("</html>");
out.close();


}


---------------------------------------------------------
PHP file



<?php
$string = "???????, ??????????????.";
echo $string;
$englishword = "Hello World!";
echo $englishword;
if (!($db = mysqli_connect('localhost','root','','tamilwords'))) {
die('SQL ERROR : Connection Failed: '. mysqli_error($db));
}
$sql = 'select tamil from childrennames';
if(!($result = mysqli_query($db,$sql))) {
die('SQL Select ERROR: '.mysqli_error($db). " - Query was: {$sql}");
}
while ($row = mysqli_fetch_assoc($result)) {
echo "{$row['tamil']}. <br/>\n";
}
mysqli_close($db);
?>

M.Mauran

unread,
Nov 27, 2009, 12:47:23 PM11/27/09
to freetamilcomputing
html கோப்பொன்றிலிருந்து யுனிகோடு எழுத்துப் பகுதிகளை மட்டும் தனியே பிரித்து எடுக்க வேண்டுமா?

php இல் இதனை என்னால் செய்ய முயற்சிக்க முடியும்.
--
மு. மயூரன் | මු. මයූරන් | M. Mauran
[ http://www.google.com/profiles/mmauran ]

Pandian R

unread,
Nov 27, 2009, 12:52:18 PM11/27/09
to freetamil...@googlegroups.com
I am sure java will treat tamil characters without any issues. I saw you are using MS Access, Make sure  about the data type you are using. I am not sure about Access But MS SQL handles these characters with nvarchar and nchar in place of varchar and nvarchar. This may be one place getting screwed up. 

Pandian R
---------------------------------------------------
*Free* software is a matter of liberty not price. You should think of "free" as in "free speech".
http://blog.grassfield.org


On Fri, Nov 27, 2009 at 11:10 PM, ravi <ravid...@googlemail.com> wrote:

Sarves K

unread,
Nov 27, 2009, 12:54:19 PM11/27/09
to freetamil...@googlegroups.com
Are you retrieving the data from database?

Make sure that
- Collation of database and the all the tables are set to utf8_general_ci (or another proper utf8)
- Characterset of the web page that you use to diplay the content is set to utf8

Then basically it should work.

Sarves

Reply all
Reply to author
Forward
0 new messages