I am using postgres 8.0.
I have a table trn.
create table trn (trn_id int, trn_file bytea);
insert into trn(1,"myFile.doc");
myFile.doc is a wordfile.
I have successfully inserted data in trn table.
Now i want to retrieve trn table and change the contents of myFile.doc.
But by using this below code i can't retrieve myFile.doc in readble (String) form....
It give me the binary string....
How i get the content of myFile.doc in readable form...
here is the snippet of my jsp page..
<% String selectedTrnId = (String)request.getParameter("trnId");
System.out.println("selectedTrnId in UpdateTranscriptedFile(jsp) ==> " + selectedTrnId);
TranscriptDAO trnDao = new TranscriptDAO();
String fileContent = trnDao.retrieveFile(Integer.parseInt(selectedTrnId));
System.out.println("******************************** ");
System.out.println("fileContent in UpdateTranscriptedFile(jsp) ==> " + fileContent);
%>
.....
.....
.....
<TR>
<TH align="right">File :</TH>
<TD align="left"><html:text property="trnFile" value="<%= fileContent %>" /></TD>
</TR>
So any how i want trn_file content in string form...and then update this content as and when require and again store in bytea format in database.
pl. help me out...
Thanks in advanced.
ketan
I have a table trn.
create table trn (trn_id int, trn_file bytea);
insert into trn(1,"myFile.doc");
myFile.doc is a wordfile.
I have successfully inserted data in trn table.
Now i want to retrieve trn table and change the contents of myFile.doc.
But by using this below code i can't retrieve myFile.doc in readble (String) form....
It give me the binary string....
How i get the content of myFile.doc in readable form...
Code:
public String retrieveFile(int trnId) {
preparedStatement = null;
connection = null;
InputStream is = null;
StringBuffer out = null;
try {
ApplicationDataSource ads = new ApplicationDataSource(Constants.DATA_SOURCE_NAME);
connection = ads.getConnection();
String selectSql = "select trn_file from trn where trn_id=" + trnId + ";";
preparedStatement = connection.prepareStatement(selectSql);
ResultSet rs = preparedStatement.executeQuery();
if(rs!=null) {
while(rs.next()) {
is = rs.getBinaryStream(1);
out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = is.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
is.close();
}
rs.close();
}
preparedStatement.close();
} catch (SQLException sqle) {
System.err.println("Retrieve content: " + sqle.getMessage());
} catch (Exception ioe) {
System.err.println("Writing stuff: " + ioe.getMessage());
}finally {
closeDatasourceWrappers();
}
return out.toString();
}
here is the snippet of my jsp page..
<% String selectedTrnId = (String)request.getParameter("trnId");
System.out.println("selectedTrnId in UpdateTranscriptedFile(jsp) ==> " + selectedTrnId);
TranscriptDAO trnDao = new TranscriptDAO();
String fileContent = trnDao.retrieveFile(Integer.parseInt(selectedTrnId));
System.out.println("******************************** ");
System.out.println("fileContent in UpdateTranscriptedFile(jsp) ==> " + fileContent);
%>
.....
.....
.....
<TR>
<TH align="right">File :</TH>
<TD align="left"><html:text property="trnFile" value="<%= fileContent %>" /></TD>
</TR>
So any how i want trn_file content in string form...and then update this content as and when require and again store in bytea format in database.
pl. help me out...
Thanks in advanced.
ketan