currently I found an alternative to fetch the string output in Java using Talend Studio:
tJava code:
String output=((String)globalMap.get("tSystem_1_OUTPUT"));
System.out.println("Printing the error code 1 : "+StringUtils.substringBetween(output,"source count:", "destination count:"));
tJava output:
Printing the error code 1 : ', '1000')
('
Expected Result:
Printing the error code 1 : 1000
However, tJava takes the result exactly between string " source count:' " and " destination count: ", so that included the bracket and all. The expected result is only to get the value 1000.
How do I apply this java code to fetch the correct output?
Haven't test this within Talend itself but try this ...
String output=((String)globalMap.get("tSystem_1_OUTPUT"));
var sourceCount = output.split("\\)")[0].split(",")[1].replace("'", "").trim();
System.out.println("Printing the error code 1 : " + sourceCount);
Related
I am trying to shirt the values with leading zero to the right when opening the csv file with Excel MS. I am using bufferedWriter.write("\\"\t"+row[4] + "\\"\t"); . The tabe and quote to display the leading zero since without it I am just getting 46 and not 046.
if(row[4].startsWith("0")){
bufferedWriter.write(";" + "\\"\t"+row[4] + "\\"\t");
}else{
bufferedWriter.write(";" + row[4]);
}
screen shot
Couple of things:
Fix the write line to properly escape the quote
bufferedWriter.write(";" + "\"\t"+row[4] + "\"\t");
This is the output (I am using the pipe/"|" instead of a new line)
2016;" 046" |2016;" 046" |2016;400|2016;400|
Remove the second tab to get rid of the extra space in your display
bufferedWriter.write(";" + "\"\t"+row[4]);
This is now the output
2016;" 046"|2016;" 046"|2016;400|2016;400|
I'm using JPL Libraries to link a Prolog program with Java interface.
I have a (working) JTextArea where I redirect everything that appears in Console, but I can't see the prolog "write" instruction.
I used this method for queries:
Query q2 = new Query(t2);
System.out.println("Query " + t2 + " is " + (q2.hasSolution()));
but when the query is false, the text in "write" parts of Prolog for example:
write('Sorry, you can''t go from the '), write(CurPlace), write(' to the '), write(Place), nl,
doesn't appear in JTextArea.
I tried also with System.out.println("first solution of " + q2 + ": X = " + q2.oneSolution().get("X")); but it doesn't work.
What happen in JTextArea is this:
Query goto(garage).
is false
but I expected also the "write" warnings contained in .pl file. For example:
write('Sorry, you don''t have the keys')
i try since some days to send one mail with different informations from child job and father job.
see my jobs below:
and my tRunJob_3
at the end of this job, i can put informations from tAggregateRow in the email, but it send several email (one mail by condition "if" approved DeinitJob --- if --- tRunJob_3)
my file generated by tFileOutputDelimited_1 in the father job contains all the information i need to put in the final mail.
1: how to display these informations in one email (no attachement) ?
2: i have this error in my console:
For input string: "7.91'7.91"
multiple points
what it means ?
EDIT:
with the modification below, it send me 1 email with the informations collected
in my tjavaflex:
code initial
// start part of your Java code
boolean loop ;
System.out.println("## START\n#");
code principal
// here is the main part of the component,
// a piece of code executed in the row
// loop
// code sample:
System.out.println("## LOAD...\n#");
if ((String)globalMap.get("message") != null) {
globalMap.put("message", (String)globalMap.get("message") + row5.mag + " qt: " + row5.qt + " p1: " + row5.p1 + "\n" ) ;
}
code final:
// end of the component, outside/closing the loop
loop = true ;
System.out.println("## END\n#");
with a if loop between tjava and tsendmail
but still have my error:
For input string: "7.91'7.91"
multiple points
I believe that most of you would be thinking that this is the same question you have heard multiple times (and answered ) about string concatenation in Java. But trust me, it is different. In fact, so different that I am even hesitant in posting it here. But anyways, here it is. I have some piece of code which goes like:
public void handleSuccess(String result)
{
result = result.trim();
MessageBox.alert("Information","Result after trimming: '" + result + "'");
result = result.substring(result.indexOf('\n') + 1);
MessageBox.alert("Information","Result after substring: '" + result + "'");
String returns = getReturns();
MessageBox.alert("Information","Returns: '" + returns + "'");
String action = getAction();
MessageBox.alert("Information","Action: '" + action + "'");
String finalResult = result + returns + action;
MessageBox.alert("Information","Final result: '" + finalResult + "'");
}
Now the situation here is that, all of these : getReturns(), result and getAction() return non blank values, and in fact the string finalResult contains the concatenated value after the last line is executed.
So, at Line 1, "result" contains "12/03/2013|04-AERTY|". The value of result remains same at end of line 1,2. getReturns() returns value 12.4724. So at end of line 3, finalResult contains "12/03/2013|04-AERTY|12.4724". getAction() returns "expt". So, at end of line 5, finalResult contains "12/03/2013|04-AERTY|12.4724|expt"
This is , when I debug or run the application in eclipse. As soon as build the same application on a UNIX system to generate a "war" file, and deploy the war on a tomcat server, the problem rears it's ugly head. When I run the application on the deployed war, the last line does not contain the concatenated value. So at the end of line 5, finalResult contains just "12/03/2013|04-AERTY|12.4724". I expected it to contain "12/03/2013|04-AERTY|12.4724|expt" as it does while running in eclipse.
I have tried stringbuffer, stringbuilder and the "+" operator as well, but nothing seems to work. I am not even getting an exception.
Can somebody help me in fixing this or at least enlightening me in what I might be doing wrong here?
Just to stress again, the code on eclipse(which is on a windows machine) and UNIX machine are exactly same. I have done a diff on them.
Here is what I get after putting the message-boxes:
Message-box 1: "Result after trimming: '12/03/2013|04-AERTY|'"
Message-box 2: "Result after substring: '12/03/2013|04-AERTY|'"
Message-box 3:"Returns: '12.4724'"
Message-box 4:"Action: '|expt'"
Message-box 5:"Final result: '12/03/2013|04-AERTY|12.4724|expt'"
Message-box 5 output is the one I receive when I execute code using eclipse
When running on deployed war, Message-box 1-4 have the same output as above, but Message-box 5 says: "Final result: '12/03/2013|04-AERTY|12.4724"
It's not clear where the extra "|" is meant to come from - if getAction() just returns expt, the result would be 12/03/2013|04-AERTY|12.4724|expt.
Anyway, I think it's safe to say that string concatenation will be working fine, and something else is wrong. You should add more diagnostics, logging everything:
public void handleSuccess(String result) {
result = result.trim();
log.info("Result after trimming: '" + result + "'");
result = result.substring(result.indexOf('\n') + 1);
log.info("Result after substring: '" + result + "'");
String returns = getReturns();
log.info("Returns: '" + returns + "'");
String action = getAction();
log.info("Action: '" + action + "'");
// It's not clear what this is meant to do. I suggest you remove it and
// use logging instead.
MessageBox.alert("Information", "The selected action is " + action, null);
String finalResult = result + returns + action;
log.info("Final result: '" + finalResult + "'");
I suspect you'll find that action is an empty string in the broken case.
Note that I've added quotes round each of the logged values, very deliberately. That means that if there's some unprintable character at the end of a string which causes problems, you should be able to detect that in the logging.
EDIT: As per the comment thread, when these were turned into message boxes (as it turns out this is running in GWT) it looks like there's something wrong with the early strings, as the closing ' isn't seen in diagnostics, in the broken case. The OP is going to investigate further.
I'm trying to query a file based on the eXist database.
Through a simple function to display the contents of the file, no problem:
XMLResource res = (XMLResource) col.getResource(resourceName);
System.out.println(res.getContent());
But when I try against making a request impossible.
String xQuery = "for $x in doc(\"" + resourceName + "\")." + "return data($x).";
ResourceSet result = service.query(xQuery);
ResourceIterator i = result.getIterator();
I have the following errors:
Exception in thread "main" org.xmldb.api.base.XMLDBException: Failed to invoke method queryP in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.StaticXQueryException: exerr:ERROR org.exist.xquery.XPathException: exerr:ERROR err:XPST0003 in line 1, column 58: unexpected token: .
at org.exist.xmldb.RemoteXPathQueryService.query(RemoteXPathQueryService.java:114)
at org.exist.xmldb.RemoteXPathQueryService.query(RemoteXPathQueryService.java:71)
at ExistAccess.main(ExistAccess.java:45)
Caused by: org.apache.xmlrpc.XmlRpcException: Failed to invoke method queryP in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.StaticXQueryException: exerr:ERROR org.exist.xquery.XPathException: exerr:ERROR err:XPST0003 in line 1, column 58: unexpected token: .
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:197)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
at org.exist.xmldb.RemoteXPathQueryService.query(RemoteXPathQueryService.java:99)
... 2 more
[B#105081caorg.apache.xmlrpc.XmlRpcException: Failed to invoke method queryP in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.StaticXQueryException: exerr:ERROR org.exist.xquery.XPathException: exerr:ERROR err:XPST0003 in line 1, column 58: unexpected token: .
I checked all my .jar file, and all of them are present... I really need help ! Thanks in advance!
Your query:
String xQuery = "for $x in doc(\"" + resourceName + "\")." + "return data($x).";
The core of the error:
err:XPST0003 in line 1, column 58: unexpected token: .
As the error message states, eXist-db recognizes an error with the "."; this period/dot is invalid XQuery. Remove the dot from the query, and you should be fine. The query text itself should look like this:
for $x in doc("/db/mycollection/mydocument.xml") return data($x)
Also, it appears your FLWOR loop is iterating over a single item - the resource. Therefore, the FLWOR is extraneous. You could refactor this as:
data(doc("/db/mycollection/mydocument.xml"))
I think you string concat make this issue, why not try to add a space after ".". Change your code like
String xQuery = "for $x in doc(\"" + resourceName + "\"). " + "return data($x).";