?
Solved

convert HEX to ASCII (.jsp)

Posted on 2003-02-18
6
Medium Priority
?
515 Views
Last Modified: 2006-11-17
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
Comment
Question by:trodak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 7980344
what output does this generate?
0
 

Author Comment

by:trodak
ID: 7982359
A hex value such as...


435744202F7075622F616E746976697275732F64617466696C65732F342E780D0A

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

CWD /pub/antivirus/datfiles/4.x
0
 
LVL 9

Accepted Solution

by:
Venci75 earned 200 total points
ID: 7992181
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
 

Expert Comment

by:CleanupPing
ID: 9059258
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
 
LVL 7

Expert Comment

by:tomboshell
ID: 9552806
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question