aspose file tools*
The moose likes JDBC and the fly likes storing the Unicodes in the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "storing the Unicodes in the database" Watch "storing the Unicodes in the database" New topic
Author

storing the Unicodes in the database

Sathish Ramadas
Greenhorn

Joined: Feb 18, 2004
Posts: 27
I have some problem with Unicode datatype. I am storing the japanese charater in the Oracle 9i database. Taking input (japanese charater) from the browser and storing into the database. Ans also i retrieving back, the browser is showing the japanese charater properly.
I have doubt in storing the japanese character in the database, will it be stored like this format (万万万上与久 in the database. The thing use we are using some reporting tool Business Objects to genereate the report using the oracle as database. We are not sure about the tool is supporting the japanese charater properly or problem with unicode storage in the dataabse.

can you please help.
Natarajan Shankar
Ranch Hand

Joined: Jun 10, 2004
Posts: 53
Hi Satish,
While storing tin Database I hope it will store as binary. So the problem might be in your program/ report tool which takes the input from the Database it might convert again to binary so you might get junk or the output what u havn't expected.

At the same time you can check passing value directly from UI to report possible, as it might give a hint.


Best Regards<br />N.Shankar<br />SCJP, SCWCD
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

"Sathish" -

Welcome to the JavaRanch! We don't have many rules around the 'Ranch, but we do require your display name to follow the JavaRanch Naming Policy.
You can change it here.


Thanks! and welcome to the JavaRanch!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Moving to the JDBC forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sathish Ramadas
Greenhorn

Joined: Feb 18, 2004
Posts: 27
hey...I write the unicode in an XML file . When i open the xml file in the browser it is showing the japanese character. so what's your opinion whether it is writing the unicode properly or not. Pls see my code. Also i have a doubt that we don't need to specify any format while storing the japanese character in the database.The database will take care of it right. The thing we need to store it in a proper datatype (NVARCHAR2 in oracle).



code Here...

<%@ page language="java" contentType="text/html; charset=Shift-JIS"%>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Shift-JIS">


<%
String XML_ROOT_TAG ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?<Sample>";
String XML_END_TAG = "</Sample>";

request.setCharacterEncoding("ISO-8859-1");
String inputValue = request.getParameter("Input");
String username = "bo6steps";
String password = "bo6steps";
String dbname = "CLXDEV";
String hostname = "njdbupora0-m";//"tkops1dsyb-v1";
String port = "2604";
Connection conn = null;
PreparedStatement ps= null;

String sql = "insert into template1(Id,JpName) values(?,?)";
String sql1 = "select * from template1";

try {
System.out.println("Creating Connection");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String connectionURL = "jdbc dbc:bo6steps";
// Attempt to connect to a driver.
conn = DriverManager.getConnection(connectionURL, username,
password);

System.out.println("got connection");
ps = conn.prepareStatement(sql);
ps.setString(1, "66");
ps.setString(2, inputValue);
int i=100;
ps.executeUpdate();

ps = conn.prepareStatement(sql1);
ResultSet rs = ps.executeQuery();
FileOutputStream outStream = new FileOutputStream ("dbDetails.xml");
String temp1=null;
String temp2 = null;
outStream.write(XML_ROOT_TAG.getBytes());
while(rs.next()){

temp2 = new String(rs.getString(2).getBytes("Shift-JIS"));
out.println(temp2);
out.println("................. ");
outStream.write(temp2.getBytes());
}
outStream.write(XML_END_TAG.getBytes());

}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
ps.close();
conn.close();
System.out.println("closed connection");
}
catch (Exception e) {
e.printStackTrace();
}

}


%>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

"Sathish",

Nathan's request to change your display name was not a suggestion. Proper display names are required. Take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

bear
Forum Bartender
Sathish Ramadas
Greenhorn

Joined: Feb 18, 2004
Posts: 27
Updated the display name....

Can anyone please look at the code help to solve the problem. I dint get any reply....pls help me.

hey...I write the unicode in an XML file . When i open the xml file in the browser it is showing the japanese character. so what's your opinion whether it is writing the unicode properly or not. Pls see my code. Also i have a doubt that we don't need to specify any format while storing the japanese character in the database.The database will take care of it right. The thing we need to store it in a proper datatype (NVARCHAR2 in oracle).



code Here...

<%@ page language="java" contentType="text/html; charset=Shift-JIS"%>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Shift-JIS">


<%
String XML_ROOT_TAG ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?<Sample>";
String XML_END_TAG = "</Sample>";

request.setCharacterEncoding("ISO-8859-1");
String inputValue = request.getParameter("Input");
String username = "bo6steps";
String password = "bo6steps";
String dbname = "CLXDEV";
String hostname = "njdbupora0-m";//"tkops1dsyb-v1";
String port = "2604";
Connection conn = null;
PreparedStatement ps= null;

String sql = "insert into template1(Id,JpName) values(?,?)";
String sql1 = "select * from template1";

try {
System.out.println("Creating Connection");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String connectionURL = "jdbc dbc:bo6steps";
// Attempt to connect to a driver.
conn = DriverManager.getConnection(connectionURL, username,
password);

System.out.println("got connection");
ps = conn.prepareStatement(sql);
ps.setString(1, "66");
ps.setString(2, inputValue);
int i=100;
ps.executeUpdate();

ps = conn.prepareStatement(sql1);
ResultSet rs = ps.executeQuery();
FileOutputStream outStream = new FileOutputStream ("dbDetails.xml");
String temp1=null;
String temp2 = null;
outStream.write(XML_ROOT_TAG.getBytes());
while(rs.next()){

temp2 = new String(rs.getString(2).getBytes("Shift-JIS"));
out.println(temp2);
out.println("................. ");
outStream.write(temp2.getBytes());
}
outStream.write(XML_END_TAG.getBytes());

}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
ps.close();
conn.close();
System.out.println("closed connection");
}
catch (Exception e) {
e.printStackTrace();
}

}


%> Can anyone please look at the code help to solve the problem. I dint get any reply....pls help me.
Hima Mangal
Greenhorn

Joined: Oct 17, 2002
Posts: 9
Hi Sathish,

In case you have managed to figure out the solution, can you please let us know about it too?

Thanks
~H
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing the Unicodes in the database
 
Similar Threads
character convertion in java
Weblogic support for Japanese Character
Japanese in JTextField without changing the IME settings everytime
Display problem with Japanese characters
problem with unicode database web application