cancel
Showing results for 
Search instead for 
Did you mean: 

how-to bind binary data into textbox

Former Member
0 Kudos

can i bind binary data into the textbox....

coz..i get human unreadable character

[B@184b867# binary data - byte array

supposingly ..i just need to convert to bytes.toString() to see the content...

yet i try but..it still return this weird character...any idea...


OutMailBean outMailBean = new OutMailBean();
outMailBean.setHost(request.getParameter("SMTP").trim());
outMailBean.setPort(request.getParameter("port").trim());
outMailBean.setMessages(request.getParameterValues("message"));    //string[]



//convert to byte array
outMailBean.setMessage(util.convertStringBufferToByteArr(bean.getMessages()));



//insert into table
Statement stmt = con.createStatement();
try {
ResultSet rs = stmt.executeQuery(squery);
try {
					
while (rs.next()) {
OutMailBean outMailBean = new OutMailBean();
outMailBean.setEmailId(rs.getString("EMAILID"));
outMailBean.setDateIn(rs.getString("DATEIN"));
outMailBean.setMessage(rs.getBytes("MESSAGE"));
System.err.println(rs.getBytes("MESSAGE").toString());
       //this will return human unreadable form........
OutMailAckBean outMailAckBean = new OutMailAckBean();
outMailAckBean.setAckDelivery(rs.getString("ACKDELIVERY"));	
outMailAckBean.setReceipient(rs.getString("RECEIPIENT"));
beanList.add(outMailBean);
beanList.add(outMailAckBean);
	}
				} finally {
					rs.close();
				}
			} finally {
				stmt.close();

Message was edited by:

yzme yzme

Message was edited by:

yzme yzme

Accepted Solutions (0)

Answers (1)

Answers (1)

Sigiswald
Contributor
0 Kudos

Hi yzme,

You need to convert the binary data to characters, a String, before you can properly display it. You say that <i>System.err.println(rs.getBytes("MESSAGE").toString());</i> prints human unreadable stuff. Maybe you need to use another character encoding, like this


byte[] message = rs.getBytes("MESSAGE");
String s = new String(message, "UTF-8"); // or "ISO-8859-1"

It all depends on how the original email message, presumably text, was stored in the database. There's no general way to convert a byte[] to a String and vice versa.

BTW, if you populate your OutMailBean using <i>outMailBean.setMessages(request.getParameterValues("message"));</i> then you're actually saying an email can have several messages and OutMailBean contains a <i>String[] messages</i> attribute. Then, you call the <i>outMailBean.setMessage</i> method which implies an email has one message and according to you comment OutMailBean contains a <i>byte[] message</i> attribute. The question is of course how you convert the <i>String[] messages</i> attribute to the <i>byte[] message</i> attribute. In other words, what does <i>util.convertStringBufferToByteArr</i> exactly do? It doesn't even convert a <i>StringBuffer</i>, but a <i>String[]</i>. What you probably want to do is something like


//OutMailBean bean
String[] messages = bean.getMessages();
StringBuffer sb = new StringBuffer();

for (int j = 0; j < messages.length; j++) {
  sb.append("message ").append(j).append("rn");
  sb.append(messages[j]).append("rnrn");
}

bean.setMessage(sb.toString().getBytes("UTF-8"));

Kind regards,

Sigiswald