Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Converting lables in to the Vietname

843790Oct 17 2006 — edited Oct 23 2006
Hi all ,
I have a block of code which is used to converting lables.
I have an excel sheet which contains the lables in the language "vietname" Now i am trying to import the excel sheet to update the table with corresponding label values of excel sheet.
Table are updating correctly, but where i am facing the problem is
" i am getting '?' symbol in the lables which doesn't have the '?' in the excel sheet". i have used CP1258 character set for converting the lables.

i have attached the code for clarification.
package beans.ml;
import jxl.*;
import java.sql.*;
import java.io.*;

public class Excel_to_DB {

public static void main(String ar[])
{
String xlfPath ="C:\\Documents and Settings\\administrator.DMMAIN\\Desktop\\from \\MT_LABEL_NAME-1_20June06.xls";
int row = 1; int colid = 0; int collabel = 3; //int collanguage = 0;
String label ="",language = "VET",encodingType = "Cp1258";
int id=0;

try{
Workbook workbook = Workbook.getWorkbook(new File(xlfPath));
Sheet wrsheet = workbook.getSheet(0);

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:qcctrlbl","db2admin","x");
PreparedStatement psmt = con.prepareStatement("insert into tmp_lang_word_conversion values(?,?,?)");

Statement smt = con.createStatement();

do{
label ="";
Cell cid = wrsheet.getCell(colid,row);
Cell clabel = wrsheet.getCell(collabel,row);


try{
if(cid.getContents().trim().equals(""))
break;
id = Integer.parseInt(cid.getContents());

psmt.setString(1,language);
psmt.setInt(2,id);
if(!language.trim().equalsIgnoreCase("ENG"))
{
ResultSet lrs = smt.executeQuery("select character_set from mt_language where language_code = '"+language+"'");
lrs.next();
encodingType = lrs.getString("character_set");
System.out.println(" ec "+encodingType);
if(!clabel.getContents().trim().equals(""))
{
psmt.setBytes(3,clabel.getContents().trim().getBytes(encodingType));
}else
{
psmt.setString(3,clabel.getContents());
}
}else
{
label = clabel.getContents();
psmt.setString(3,label);
}
}catch(Exception ex)
{
label = clabel.getContents();
psmt.setString(3,label);
ex.printStackTrace();
}

if( !cid.getContents().trim().equalsIgnoreCase(""))
{
try{

psmt.executeUpdate();
}catch(Exception ex)
{
try{
PreparedStatement psmtinst = con.prepareStatement("update lang_word_conversion set converted_label = ? where label_id = ? and language_code = ? ");
if(!language.trim().equalsIgnoreCase("ENG"))
{
ResultSet lrs1 = smt.executeQuery("select character_set from mt_language where language_code = '"+language+"'");
lrs1.next();
encodingType = lrs1.getString("character_set");
if(!clabel.getContents().trim().equals(""))
{
psmtinst.setBytes(1,clabel.getContents().trim().getBytes(encodingType));
}else
{
psmtinst.setString(1,clabel.getContents());
}
}else
{
label = clabel.getContents();
psmtinst.setString(1,label);
}

psmtinst.setInt(2,id);
psmtinst.setString(3,language);
psmtinst.execute();
}catch(Exception ex1)
{
ex1.printStackTrace();
}
}
}
row++;
System.out.println(" "+id+" "+label);
}while(true);
workbook.close();
System.out.println("Completed ");
}catch(Exception ex){
System.out.println("psmt "+row);
ex.printStackTrace();

}
}
}

Pls advise me

Thanks in advance
malli
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 20 2006
Added on Oct 17 2006
1 comment
116 views