---------- 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);
?>