I have store Hindi data in MySQL database. See the following image-
Now I want to fetch that data and display on my JSP page, but when I'm trying to fetch data in my java code I'm getting text into the following formate
UID= ????/??????????/????/?????/?????/Test upgrade/1
UID= ????/??????????/??????/??????/??????????/159/1
UID= ????/??????????/??????/??????/??????????/190/1
UID= ????/??????????/??????/??????/??????????/194/1
UID= ????/??????????/??????/???????/?????? (??.)/730/1
UID= ????/??????????/??????/???????/?????? (??.)/742/1/1
UID= ????/??????????/??????/???????/?????? (??.)/732/1
UID= ????/??????????/??????/??????/??????/98/8/1
UID= ????/??????????/??????/??????/??????/48/10/1
Referring to this question I have changed my database charset to "utf8_unicode_ci", but Still not working. I have written following code to fetch the data
// Method to fetch data from database.
public void getDetails()
{
// Establish connection to the database
DBConnection bdConnection = new DBConnection();
java.sql.Connection connectionObject = null;
java.sql.ResultSet resultSetObject;
java.sql.PreparedStatement preparedStatementObj = null;
// Get DB connection.
connectionObject = bdConnection.getDbConnection();
// Check if connection not null..?
if (connectionObject != null)
{
// Query String.
String strQuery = "SELECT * FROM tbl_test_master";
try
{
preparedStatementObj=connectionObject.prepareStatement(strQuery);
// Execute Query and get query result in ResultSet Object.
resultSetObject = preparedStatementObj.executeQuery(strQuery);
//Process the result
while(resultSetObject.next())
{
String strUserId=resultSetObject.getString("user_id");
System.out.println("UID= "+strUserId);
}
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Following is my "DBConnection" class--
public class DBConnection
{
// Create Connection Object.
public static Connection connectionObject;
//
//Method Name: getDbConnection()
//Purpose: This is generic method to establish connection to the database.
//
public Connection getDbConnection()
{
try
{
// Load the Drivers
Class.forName("com.mysql.jdbc.Driver");
// URL string to connect to the database.
// Production Server
String strURL = "jdbc:mysql://xx.xx.xxx.xxx:xxxx/my_db?user=db_user&password=db_pass";
// Establish the connection.
connectionObject = (Connection) DriverManager.getConnection(strURL);
System.out.println("Connection Successfull");
}
catch (Exception e)
{
System.out.println(e);
}
return connectionObject;
}
//
// Method Name: closeConnection()
// Purpose: Generic method to disconnect database connection.
//
public void closeConnection(Connection connectionObj )
{
try
{
connectionObj.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
Thank you..!