shell to find out DBCP ( try - catch ) in java


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell to find out DBCP ( try - catch ) in java
# 1  
Old 06-17-2011
shell to find out DBCP ( try - catch ) in java

i need a shell to find out DBCP in Java

The complete spec is here.


shell file can be as follows
Code:
if ( input fileS is in the format of wrong1.txt ) {

Print the fileS name.

}


wrong1.txt
========
Code:
DataBaseConnection dbconn = new DataBaseConnection(connectionString);
try{
something...
somefuntion(dbconn,...)
dbconn..
..
..
}catch{
print excecption;
}finally{
dbconn.destroy();
}

           ---->> here connection with DB is outside of Try block -->> is wrong.


correct1.txt
========
Code:
DataBaseConnection dbconn = null;
try{
dbconn = new DataBaseConnection(connectionString);
something...
somefuntion(dbconn,...)
dbconn..
..
..
}catch{
print excecption;
}finally{
dbconn.destroy();
}

NB:
The line --> DataBaseConnection dbconn = new DataBaseConnection(connectionString);
may change (i mean it will not be exactly as it is in all the input files)


.
# 2  
Old 06-17-2011
does this work ? (not tested)
Code:
find yourPath -name "*.java" |xargs awk '/try{/{t=1} /}catch/{t=0} (!t && $0~/new DataBaseConnection\(/){print FILENAME}'

This User Gave Thanks to sk1418 For This Post:
# 3  
Old 06-17-2011
Thanks Mr.sk1418..

Great.. wonderful.. in one line you have did that.

But i am getting output Partially only.

Problem is:
i am getting Problematic file's list , But list of files NOT containing the word "new DataBaseConnection" also getting..


.
# 4  
Old 06-17-2011
Quote:
Originally Posted by linuxadmin
Thanks Mr.sk1418..

Great.. wonderful.. in one line you have did that.

But i am getting output Partially only.

Problem is:
i am getting Problematic file's list , But list of files NOT containing the word "new DataBaseConnection" also getting..

.
is that mean that you want all java files that don't contain "new DataBaseConnection(...)" to be listed out as well?

does the grep command help?

Code:
grep -lv "new DatabaseConnection" *.java

# 5  
Old 06-17-2011
oh.. i am sorry.. i wrote wrongly.

what i mean is :

the code

Code:
find yourPath -name "*.java" |xargs awk '/try{/{t=1} /}catch/{t=0} (!t && $0~/new DataBaseConnection\(/){print FILENAME}'

is working. But listing in correct1.txt file format. (as in my first post)

i changed the code as

Code:
find yourPath -name "*.java" |xargs awk '/try{/{t=1} /}catch/{t=0} (t && $0~/new DataBaseConnection\(/){print FILENAME}'  
--> with only t NOT !t

Then i am getting in wrong1.txt file format (as in my first post)
But here the problem is :
the java files Does not containing any database connection is also listing...

i know i did wrong as i deleted the ! charector from t.

but..

could you please change the code to get all the *.java files in Wrong1.txt format Alone.

.
# 6  
Old 06-17-2011
here i made some dummy java file, and my initial command (with "!t") gives the right result, the java files, which have creating connection statement outside the try/catch block.
# 7  
Old 06-17-2011
yes sk1418,

with dummy java files its working fine. and I am sorry I cannot provide you the original details.

Thank you for your time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cannot find java, gcc, Oracle on RedHat 7.2

We received Linux RedHat. I tried java -versionno result gcc -c no result I cannot even find Oracle version or directory Do you know if JAVA, gcc, Oracle are supposed to come with Linux by default? Thanks, (3 Replies)
Discussion started by: digioleg54
3 Replies

2. Homework & Coursework Questions

Java doesnīt find the CLASSPATH (System variable)

1. The problem statement, all variables and given/known data: As a excercise I have to compile a program (Hello2.java) with a class file (HelloText.java) in another directory. (As you seen in the screenshot) Iīm setting a PATH and a CLASSPATH (system variables). Itīs working without a... (2 Replies)
Discussion started by: MenschTown
2 Replies

3. Shell Programming and Scripting

How to catch errors in a shell script ( multiple commands )?

Hi I have a shell script like that Main() { DAY=$(date +"%d-%m-%Y") TIME=$(date +"%T") Command 1 Command 2 ... Command n } I would like to catch errors from all commands in Main() and write these errors into a file , something likes this: Main if < error > then echo... (3 Replies)
Discussion started by: bobochacha29
3 Replies

4. Shell Programming and Scripting

How to run java from shell

Hi All, I am trying to run a grep command which creates an output file. Then I will run a java file which take that file and process that. My java file uses other java files and library jars. I have tried below code but I am getting compilation error,it can not find other java files in same... (1 Reply)
Discussion started by: kmajumder
1 Replies

5. UNIX for Dummies Questions & Answers

find/xargs/*grep: find multi-line empty "try-catch" blocks - eg, missing ; not in a commented block

How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases? This would seem to involve find, xargs, *grep, regex, etc. In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Discussion started by: lifechamp
0 Replies

6. Shell Programming and Scripting

Shell script to catch PL/SQL return values

I tried searching the forum for similar posts but its closed now. Would appreciate any help on this. I am trying to capture return value from a select query into a variable. DB is Oracle I am able to spool it to a file but I donot intend to use it. Here is my script that does not work ;) I... (27 Replies)
Discussion started by: monie2717
27 Replies

7. Shell Programming and Scripting

Unable to find java command

Hi All, Am trying to start a server by using the startup shell script. But am getting java command not found. Can anyone guide me in which path i need to check for all the java commands and also how do i chk the version of java being installed on linux box? Thanks (3 Replies)
Discussion started by: Ashok_oct22
3 Replies

8. Shell Programming and Scripting

How to catch ENTER key inside the shell script?

Hi, I have a script in which i have to ask user to press the ENTER key to proceed further. can you please help me how can i achive this in my scripting? echo "All the executables builded Successfully " echo " Press Enter to Go Back to the Main Menu" ... (2 Replies)
Discussion started by: plaban.rout
2 Replies

9. Shell Programming and Scripting

Shell script to catch PL/SQL return values

Hello, I need some help from the experts on PL/SQL and Shell scripting. I need a shell script that runs a PL/SQL procedure and gets the values returned from the PL/SQL procedure into the shell variables. The PL/SQL procedure returns multiple values. I was able to assign a single return value... (1 Reply)
Discussion started by: Veera_Raghav
1 Replies

10. Linux

Help req for...shell script to catch "db2 connect" errors ...

Hello friends, Assume that, I am trying to execute a "db2 connect" command from Linux shell prompt via a shell script called "sample" sample db2 connect to bas39 $sample If the database is not present its should display a custom error message by catching the error message given by db2.... (1 Reply)
Discussion started by: frozensmilz
1 Replies
Login or Register to Ask a Question