• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with Encoding SQL

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone


This is a problem related to Encoding.

I am uploading a particular unicode file in SQL server database in BLOB datatype. And later on I am retrieving that file and sending it as XML to the client bean. BUt when I parse the XML and regenerate the file at the client end, somehow the file is corrupted and is not opening properly. Can anyone tell where the problem lies.


Following are the code snippets :


Uploading the File
===================





File f2 = new File("D:\\form\\File1.ngf");

FileInputStream is = new FileInputStream(f2);
int i = (int)f2.length();
pstmt.setBinaryStream(1, is,(int)f2.length());


iResult = pstmt.executeUpdate();





Creating the XML
=================


java.io.InputStream fin =(InputStream) RS.getBinaryStream(1);

formXML.append("<FormBuffer>");
StringBuffer strBuff = new StringBuffer(1024);
int len = 0;

if (!RS.wasNull()) {
byte[] buf = new byte[2048];
while(true) {
int size = fin.read(buf);
if (size > 0) {
String sss = new String(buf, 0, size);
strBuff.append(sss);
len += size;
} else {
break;
}
}
fin.close();
}




Reading the XML and creating file @ client java program
==========================================================


File f1 = new File("D:\\New.ngf");
f1.createNewFile();
FileOutputStream fou = new FileOutputStream(f1);
int nRead;
int nTot=0;

//FOrm Buffer is the STRING value of the retireved
fou.write(formBuffer.getBytes());
fou.close();
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Sumit",

Please read your private messages regarding an important announcement.

Rob
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic