If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > jdbc text codeset conversion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-14-03, 11:05
tomasovj tomasovj is offline
Registered User
 
Join Date: Nov 2003
Posts: 2
Question jdbc text codeset conversion

how can i setup automatic codeset conversion of text type column?
IFX_CODESETLOB parameter in connection url don't work (blob not found). i tried set this parameter to 0 or some value ...
Reply With Quote
  #2 (permalink)  
Old 11-14-03, 21:10
Amit Dandekar Amit Dandekar is offline
Registered User
 
Join Date: Oct 2003
Posts: 29
Not sure why you are getting blob not found error .
IFX_CODESETLOB seems to work only with the methods from
java.sql.PreparedStatement interface
i.e. PreparedStatement::setAsciiStream()
and PreparedStatement::getAsciiStream()
Make sure that you have set CLIENT_LOCALE and DB_LOCALE property to correct value.

If you are using methods from jaca.sql.Clob interface ,
I think you need to convert using JDK methods as shown
in Informix JDBC manual
http://publibfi.boulder.ibm.com/epubs/pdf/ct1utna.pdf
page 6-22.

Here is a code sample which inserts and fetches from a
clob column

Your connection url will look something like this
String url =".........;CLIENT_LOCALE=en_US.CP1252;IFX_CODESET LOB=1;DB_LOCALE=en_US.8859-1;......";


public static void insertStuff(Connection conn) throws SQLException , IOException
{

try
{
Statement stmt = conn.createStatement();
stmt.executeUpdate("drop table tab1");
stmt.close();
}
catch (SQLException e)
{
System.out.println(e);
}

try
{
Statement stmt = conn.createStatement();
stmt.executeUpdate("create table tab1 (col1 clob)");
}
catch (SQLException e)
{

System.out.println(e);
}

PreparedStatement pstmt = conn.prepareStatement("insert into tab1 (col1) values (?)");
File f = new File("c:\\sample.txt");
long size = f.length();
InputStream is = new FileInputStream(f);
// this will codeset convert text from CLIENT_LOCALE codeset
// to DB_LOCALE codeset
pstmt.setAsciiStream(1,is,(int)size);
pstmt.execute();
pstmt.close();
}


public static void getStuff(Connection conn) throws SQLException , IOException
{
PreparedStatement pstmt = conn.prepareStatement("select (col1) from tab1");
ResultSet rs = pstmt.executeQuery();

while(rs.next())
{
// this will codeset convert text from DB_LOCALE codeset
// to CLIENT_LOCALE codeset
InputStream is = rs.getAsciiStream(1);
byte[] recv = new byte[is.available()];
is.read(recv);
is.close();
}

}
Reply With Quote
  #3 (permalink)  
Old 11-15-03, 02:48
tomasovj tomasovj is offline
Registered User
 
Join Date: Nov 2003
Posts: 2
thank you for you reply.
i tried use this with com.borland.dx.sql.dataset classes in borland JBuilder9.
Reply With Quote
  #4 (permalink)  
Old 11-15-03, 11:52
am_dan am_dan is offline
Registered User
 
Join Date: Nov 2003
Posts: 3
I made a mistake in earlier post
IFX_CODESETLOB needs to be set to zero !
Setting it to one does not make much of sense
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On