• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

convert HEX to ASCII (.jsp)

I have a field (type=text) called "data_payload" in a MySQL database that stores a hex value.  When I display that to a .jsp page I need to convert it to ASCII before displaying it.  I tried several ways but I don't think I am on the right track.  So I am posting what I started with.  If anyone could help that would be great.
----------------------------------------------------
<%
Driver DriverrsAllData = (Driver)Class.forName(connIDS_DRIVER).newInstance();
Connection ConnrsAllData = DriverManager.getConnection(connIDS_STRING,connIDS_USERNAME,connIDS_PASSWORD);
PreparedStatement StatementrsAllData = ConnrsAllData.prepareStatement("SELECT hostname,data_payload,timestamp,sig_name,ref_id, event.cid  FROM data,event        LEFT JOIN signature ON (event.signature = signature.sig_id)        LEFT JOIN sig_reference ON (event.signature = sig_reference.sig_id)        LEFT JOIN sensor ON (event.sid = sensor.sid)  WHERE data.sid = event.sid AND        data.cid = event.cid   AND        data.cid = " + rsAllData__ColParm2 + " AND event.sid=" + rsAllData__ColParm + "");
ResultSet rsAllData = StatementrsAllData.executeQuery();
boolean rsAllData_isEmpty = !rsAllData.next();
boolean rsAllData_hasData = !rsAllData_isEmpty;
String rsAllData_data_string;
Object rsAllData_data;
int rsAllData_numRows = 0;
%>

-------------------------------------------------

<%=(((rsAllData_data_string = rsAllData.getString("data_payload"))==null || rsAllData.wasNull())?"":rsAllData_data_string)%>
0
trodak
Asked:
trodak
1 Solution
 
Venci75Commented:
what output does this generate?
0
 
trodakAuthor Commented:
A hex value such as...


435744202F7075622F616E746976697275732F64617466696C65732F342E780D0A

once converted to ascii it should look like this...

CWD /pub/antivirus/datfiles/4.x
0
 
Venci75Commented:
try this:
String str = "435744202F7075622F616E746976697275732F64617466696C65732F342E780D0A";
StringBuffer buff = new StringBuffer();
for (int i = 0; i<str.length()/2; i++) {
  buff.append((char)Integer.parseInt(str.substring(i*2, 2)));
}
System.out.println(buff.toString());
0
 
CleanupPingCommented:
trodak:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
tomboshellCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept a comment
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thomas Boshell
EE Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now