robotframeworkでは、バイト配列をStringに変換できるコードを記述する必要があります。しかしその前に、バイト配列のサイズについて知る必要がありますか?ロボットフレームワークのバイト配列を文字列に変換する
私はこの1つ試してみました:例えば、あなたがバイトを持っている場合は、[]あなたは 新しい文字列(バイト[]、文字セット)を使用して文字列に変換することができ
@SuppressWarnings("deprecation")
public static byte[] retrievePolicy(String aPolicyNumber) {
String METHOD_NAME="retrievePolicy";
byte[] myBinData = null;
Connection myConnection = null;
String mySelectSql = "SELECT PSD_BIN_DATA FROM XAT_POLICY_STUB_DATA WHERE PSD_POLICY_NBR = ?";
String myWorkingQuerySelect;
//Statement myStmt = null;
PreparedStatement myPreparedStatement = null;
String myJndiName;
try {
DataSource myDataSource;
myJndiName = AllcorpProperties.getProperty(ALLIANCE_STUB_DATASOURCE_JNDI_NAME);
myWorkingQuerySelect= mySelectSql;
myDataSource = ServiceLocator.obtainDataSource(myJndiName);
if(myDataSource!=null) {
myConnection = myDataSource.getConnection();
if(myConnection != null){
//myStmt = myConnection.createStatement();
myPreparedStatement = myConnection.prepareStatement(myWorkingQuerySelect);
myPreparedStatement.setString(1, aPolicyNumber);
ResultSet resultSet = myPreparedStatement.executeQuery();
if (resultSet != null && resultSet.next()) {
Blob myBlob = resultSet.getBlob(1);
if (myBlob != null) {
myBinData = myBlob.getBytes((long) 1, (int) myBlob.length());
}
}
}else{
PolicyServiceException myPolicyServiceException = new PolicyServiceException(new AllcorpException(),
EXCEPTION_OBTAINING_CONNECTION,
PolicyDAO.CDB_COMMUNICATION_ERROR, METHOD_NAME,BUSINESS_FUNCTION_NAME);
AllcorpLogger.error(CLASS_NAME,myPolicyServiceException);
throw myPolicyServiceException;
}
}else{
PolicyServiceException myPolicyServiceException = new PolicyServiceException(new AllcorpException(),
EXCEPTION_STATEMENT_GET_DATASOURCE,
PolicyDAO.CDB_COMMUNICATION_ERROR, METHOD_NAME,BUSINESS_FUNCTION_NAME);
AllcorpLogger.error(CLASS_NAME,myPolicyServiceException);
throw myPolicyServiceException;
}
} catch (SQLException mySQLException) {
AllcorpLogger.error(CLASS_NAME,new PolicyServiceException(mySQLException,
"Error occurred while retreiving policy from stub DB for policy number "+aPolicyNumber,"SDBURTP",METHOD_NAME,BUSINESS_FUNCTION_NAME));
} catch(AllcorpInfrastructureException myAllcorpInfrastructureException)
{
PolicyServiceException myAllcorpException = new PolicyServiceException(
myAllcorpInfrastructureException, "Exception while obtaining the data source ",
"STUBDBRP", METHOD_NAME, BUSINESS_FUNCTION_NAME);
AllcorpLogger.error(CLASS_NAME, myAllcorpException);
}
catch (Exception myException) {
AllcorpLogger.error(CLASS_NAME,new PolicyServiceException(myException,
"Error occurred while retreving policy from StubDB for policy number " +aPolicyNumber,"STUBDRP2",METHOD_NAME,BUSINESS_FUNCTION_NAME));
}finally {
try {
if (myPreparedStatement != null) {
myPreparedStatement.close();
}
if(myConnection != null){
myConnection.close();
}
} catch (SQLException myException) {
AllcorpLogger.error(CLASS_NAME,new PolicyServiceException(myException,
"Error closing prepared statement object","SDBURTP1",METHOD_NAME,BUSINESS_FUNCTION_NAME));
}
}
return myBinData;
}
私は(BLOB)が必要ポリシー –
でこれを行うことができます。あなたは大きなコードを投稿しましたが、どこに問題があるのか分かりません。 'new String(byte [] bytes)'や 'DatatypeConverter.printBase64Binary(byte [] val)'を使用できない理由を明確にし、可能であればコードサンプルを減らしてください。 – Rhayene