Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Encoding SQL  RSS feed

 
Smith Sh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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();
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sumit",

Please read your private messages regarding an important announcement.

Rob
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!