Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Gaurav Kr. Arora

Ranch Hand
+ Follow
since Feb 20, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gaurav Kr. Arora

Hi,

I am new to ant and before sending mail to this list I explored the issue on google but didn't get any satisfactory results.

In one of my project, I require to run the below sql task in a different jvm or a different process.



Actually in my build.xml file, I call a junit test using junit task and in that task I use fork=yes so that it runs in a different jvm.

But before running the junit task I need to run the sql task, but somehow it happens that both sql task and junit tasks are running in same jvm which I don't want.

Could you please help me in making sure that the sql task which I run should run in a separate jvm / process ? Can we specify fork=yes or some other attribute to do this?

Thanks!
5 years ago
Hi,

I am facing issue while running a sql script using ant task sql.
In my sql I have a package and when I run the package from sql developer console, it gets compiled successfully but when i run using ant command, it gives below error:

Failed to execute: FUNCTION get_result (p_transaction_id IN NUMBER, p_result_type IN VARCHAR2) RETURN VARCHAR2
java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:462)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:405)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:931)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:481)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:205)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:548)


The .sql file, contains the below piece:



the way I run using ant is:




Please help in resolving this.
5 years ago
Hi,

I am facing issue while running a sql script using ant task sql.
In my sql I have a package and when I run the package from sql developer console, it gets compiled successfully but when i run using ant command, it gives below error:

Failed to execute: FUNCTION get_result (p_transaction_id IN NUMBER, p_result_type IN VARCHAR2) RETURN VARCHAR2
java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:462)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:405)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:931)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:481)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:205)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:548)


The .sql file, contains the below piece:

CREATE OR REPLACE PACKAGE UTIL
AS
FUNCTION get_result (p_lot IN VARCHAR2,
p_result_type IN VARCHAR2,
p_transaction_id IN NUMBER := NULL)
RETURN VARCHAR2;

FUNCTION get_result (p_transaction_id IN NUMBER,
p_result_type IN VARCHAR2)
RETURN VARCHAR2;


PROCEDURE change_mes_header_status (p_sakey IN NUMBER,
p_status IN VARCHAR2,
p_date_modified IN DATE,
p_error_message IN VARCHAR2);

END UTIL;

the way I run using ant is:

<sql driver="oracle.jdbc.driver.OracleDriver"
url="jdbcracle:thin:@${jdbc.connectstring}"
userid="${sys_user} as sysdba"
password="${sys_user_password}"
print="yes"
showheaders="true">

<transaction src="/tmp/Sample.sql"/>
</sql>


Please help in resolving this.
Hi,

I have below requirement and newbie in db testing:

Get a schema from DB. Get a table from schema and find out if a column name say A of that table matches with any other column in any other table in the schema.
If it matches, then find out the column data type and verify if it is same as that of column A.

For e.g, if there are 10 tables and in table 1 there is a column Dept. whose data type is varchar2(50). Now I want to search "Dept." column in all the tables, and if I find this column, I need to get its data type and verify if it matches with varchar2(50).

This is a small case with 10 tables.

Hope I have put my requirement clearly.

I can do it manually but want to automate the scenario. Will any tool/api help in such kind of scenarios?

Please let me know how I can go about testing such kind of scenarios. Any help/suggestions in this regard will be highly appreciated.

Thanks!
6 years ago

Koen Aerts wrote:I haven't tried it myself, but did you try to execute the script directly, instead of as an argument to bash; i.e.


The first line in your script already ensures that bash will be used. Also, is your script really in the root directory?



Yes, that is fine, I just removed the actual file name and simply put /TestFile.txt which shows it in root. Am sorry for that.
But my major concern is how to return the exact number found by MY_VAR variable to the calling program.
6 years ago
Hi,

Am a beginner in shell scripting and stuck at a point.

Below is my shell script:

I call this script from ant and pass a file which contains a number >0. $1 in below script is file path.

file.sh
----------


#!/bin/bash
export MY_VAR=$(cat $1 | grep -E "^[0-9]+$")
echo newResult:${MY_VAR}
exit ${MY_VAR}


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


The above script should return MY_VAR to calling ant script. But it always return 255 and I don't get correct value. Also it shows [exec] : numeric argument required error.

Below is ant piece of code which calls it:

<exec executable="/bin/bash" resultproperty="count">
<arg value="/file.sh"/>
<arg value="/TestFile.txt"/>
</exec>

Please help.

Thanks!
6 years ago
Hi,

Am using RMI Spring capablilites and new to this framework.

In my application there is a client which access a service running on server using RMI Spring. Now, if maximum no. of users to that service connect, connection refuse exception is thrown and I am catching it and then transferring the control to another server which runs a backup service and performs the same task.
The task is simple. We are adding user names to an arraylist.

Problem: Arraylist to which users are getting added is local to each of the server and when control transfers to new server after exception has occured, the users get added to the arraylist which was created at the new server.

How can the same arraylist object be shared across the servers/application, so when the exception occurs or doesn't occur, program continues to add usernames in the same arraylist?

Please suggest.

Thanks.
Hi,

I am in search of a rule engine api which stores rules in database and allows accessing them in java program. I found drools, ilog jrules etc. but all of them store in drl text based file or in excel. They are able to connect to database and perform operations on facts.

If you are aware of a rule engine which stores rules in database like oracle and is easliy configurable, please let me know.

Am sorry if I have posted this at a wrong forum.

Thanks.

James Sabre wrote:I assume that behind the scenes you are using the JavaMail API to send the email. In which case you need to add a method to your framework that allows you to send a MimeMultipart attachment. There are examples of how to do this in the JavaMail distribution.

Note - JavaMail Base64 encodes binary data which means it only contains ASCII characters.



I don't want to send the image as an attachment. Instead I want to send it as a message body. How can we achieve this?
6 years ago
Hi,

The query seems complicated to me because of some constraints.
Constraints:
Have to use String message which should contain image. Not aware how can I convert a gif/jpeg/bmp/png image to java string object.
This string message object will be passed to one of my framework methods send(String type, String subject, String message) to send an email. In my email I want that image to come properly and shown to the user. there is no option to pass the image. It needs to be passed as String message.
Internally the send method of the framework will create MimeMessage etc. and send email.
Type of the email will be text/html.

What could be the best possible solution to send a image as a message body when the method send takes only String argument?

Thanks
6 years ago

Rob Spoor wrote:You can make the choice a non-capturing group by starting it with (?: instead of just (. Then put the entire thing in a capturing group:
Now you will only have one group, which is the entire String.



Got it Rob!! This is what I like the most about Code Ranch! People here dedicate their time to help others!!
Thanks a ton Rob and all of you who contributed to this post!!
6 years ago

Wouter Oet wrote:What does group(0) return?



Yes it returns January2011, the one what I want. It is same as result.group(). But, I am using the loop starting from 1 till the max size. The code is generic and is used for other pattern matching also. So, for this particular pattern, can't change starting from 0.
We need the one starting from 1 and the only option left is to change in regex and not in code.

Please advise.
Thanks.
6 years ago

Matthew Brown wrote:Get rid of the [...] brackets. They have a special meaning in a regular expression, and they aren't doing what you need here. Replace them with (...).

You should also remove the +, as you only want the month to appear once (e.g. you don't want "JanuaryMarch2011" to validate).

Finally, although it's not necessary, your outer (...) aren't doing anything useful, so you might as well remove them.



Thanks for the useful reply...
Here, one more issue comes when I use the below mentioned regex:
s.findInLine("^(January|February|March|April|May|June|July|August|September|October|November|December)\\d{4}$");

for (int i=1; i<=result.groupCount(); i++)
System.out.println(result.group(i));

Output of above snippet is January, since small brackets are ended before the year \\d{4} regex..but I need the whole string to come as a group.. Other possible solution is to use result.group(). this returns January2011 but I can't use it as my code is generic to other regex patterns also and I am using result.group(i) and not result.group().

Please let me know, if you require more inputs. Would appreciate if you can help in resolving this as well.
6 years ago
Hi,

If the input to below program is Jan2011 or January2011 or abc2011, it validates. I want that only full months should succeed. For e.g., Jan2011 is invalid and January2011 is valid.

- Constraint here is I can use only Scanner and findInline methods.


Could you please help in creating a correct regex?

Thanks.
6 years ago

Mike Simmons wrote:I think you need to look into the differences between findInLine(), find(), and matches().



Scanner doesn't has find and matches method and I have to use Scanner and findInline method (as it is already present in my framework)
Please help in creating regex.
6 years ago