san patil

Greenhorn
+ Follow
since Mar 30, 2003
Merit badge: grant badges
For More
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 san patil

Suggestions why it is failing when code seems to be alright.
20 years ago
Hi,
I have written the below code to run the unix shell script.
----------------------------------------------------------
public String runProcess(String aProcessName)
{
String vStatus="";
try
{
aProcessName = "/opt/jrun/restart/restart.sh";
Process process = Runtime.getRuntime().exec(aProcessName);
try
{
process.waitFor();
}
catch(InterruptedException ie)
{
vStatus = "Error : interrupted while waiting for app to end"+ie;
}

int vExitStatus = process.exitValue();
if (vExitStatus == 0)
{
// success
vStatus = "Success";
}
else
{
//Failed- It is faling with vExitStatus =1;
vStatus = "Error : Failed to execute the script." +vExitStatus;
}
} catch (Exception e)
{
vStatus = "Error : Unable to execute the script."+e;
}
return vStatus;
}
----------------------------------------------------------
Any suggestions!
Thanks,
San
20 years ago
Hi,
I am looking for solution to encode and decode the password. I have developed a web application where I have stored User names and passwords in a dat file. I want to protect passwords from administrator.
Any solutions?
Thanks,
San
20 years ago
Hi,
I have a unix script (san.sh). I want to call this script through a servlet.
Please suggest!
Thanks,
san
20 years ago
I agree with what you have mentioned.
Thanks a lot for your explanation!
san
20 years ago
Actually code is working fine in both the scnerio's.
Freeing the connection at the end of a method,
is nothing but returning it back to the pool, so that it is available for another request so it can offcourse be used.
20 years ago
Hi,

I have come across the following scenerio's on connection pooling at my work.
I am really not sure whether it is a better approach to initialize a connection object inside each and every method of Adapter class or just initialize it once in a constructor and eventually use it and release it upon usage.
The reason I have this doubt in my mind is, I have worked on the same issue with both the approaches and both are working fine.

Scenerio 1.
Initilizing the connection object in each and every method.
Code goes as below..
Class xxxAdapter
{
Connection conn=null;
Statement stmt=null;
public xxxAdapter()
{
}
public void getName(int param1, String param2) throws Exception
{
String sql="SELECT EMP_NAME FROM EMP WHERE EMP_ID="'+param1+"' AND EMP_DEPT='"+param2+"'";
try
{
conn = DBConnectionPool().getConnection(); // Initilize the connection object to get the connection from pool
stmt= conn.createStatement(sql);
--- REST CODE GOES HERE ----
}
catch(SQLException e)
{
// Exception caught
}
finally
{
if(conn != null)
DBConnectionPool().freeConnection(conn); //return the connection to the pool
}
}
public void getDetails(String param1) throws Exception
{
String sql="SELECT * FROM EMP WHERE EMP_NAME="'+param1+"' ";
try
{
conn = DBConnectionPool().getConnection(); // Initilize the connection object to get the connection from pool
stmt= conn.createStatement(sql);
--- REST CODE GOES HERE ----
}
catch(SQLException e)
{
// Exception caught
}
finally
{
if(conn != null)
DBConnectionPool().freeConnection(conn); //return the connection to the pool
}
}
Scenerio 2.
Initilizing the connection in constructor only once and use it when needed.
Code goes as below..
Class xxxAdapter
{
Connection conn=null;
Statement stmt=null;
public xxxAdapter()
{
conn = DBConnectionPool().getConnection(); // Initilize the connection object to get the connection from pool
}
public xxxAdapter(Connection connIn)
{
conn = connIn; // Initilize the connection object with the connection object of calling class.
}
public void getName(int param1, String param2) throws Exception
{
String sql="SELECT EMP_NAME FROM EMP WHERE EMP_ID="'+param1+"' AND EMP_DEPT='"+param2+"'";
try
{
stmt= conn.createStatement(sql);
--- REST CODE GOES HERE ----
}
catch(SQLException e)
{
// Exception caught
}
finally
{
if(conn != null)
DBConnectionPool().freeConnection(conn); //return the connection to the pool
}
}
public void getDetails(String param1) throws Exception
{
String sql="SELECT * FROM EMP WHERE EMP_NAME="'+param1+"' ";
try
{
stmt= conn.createStatement(sql);
--- REST CODE GOES HERE ----
}
catch(SQLException e)
{
// Exception caught
}
finally
{
if(conn != null)
DBConnectionPool().freeConnection(conn); //return the connection to the pool
}
}
Which approach would be better? Awaiting to have your comments..
20 years ago
Hi Java Guru's,
I have come across the following scenerio's on connection pooling at my work.
I am really not sure whether it is a better approach to initialize a connection object inside each and every method of Adapter class or just initialize it once in a constructor and eventually use it and release it upon usage.
The reason I have this doubt in my mind is, I have worked on the same issue with both the approaches and both are working fine.
Could you please le me know which approach should I go for and wny?
Scenerio 1.
Initilizing the connection object in each and every method.
Code goes as below..
Class xxxAdapter
{
Connection conn=null;
Statement stmt=null;
public xxxAdapter()
{
}
public void getName(int param1, String param2) throws Exception
{
String sql="SELECT EMP_NAME FROM EMP WHERE EMP_ID="'+param1+"' AND EMP_DEPT='"+param2+"'";
try
{
conn = DBConnectionPool().getConnection(); // Initilize the connection object to get the connection from pool
stmt= conn.createStatement(sql);
--- REST CODE GOES HERE ----
}
catch(SQLException e)
{
// Exception caught
}
finally
{
if(conn != null)
DBConnectionPool().freeConnection(conn);//return the connection to the pool
}
}
public void getDetails(String param1) throws Exception
{
String sql="SELECT * FROM EMP WHERE EMP_NAME="'+param1+"' ";
try
{
conn = DBConnectionPool().getConnection(); // Initilize the connection object to get the connection from pool
stmt= conn.createStatement(sql);
--- REST CODE GOES HERE ----
}
catch(SQLException e)
{
// Exception caught
}
finally
{
if(conn != null)
DBConnectionPool().freeConnection(conn);//return the connection to the pool
}
}
Scenerio 2.
Initilizing the connection in constructor only once and use it when needed.
Code goes as below..
Class xxxAdapter
{
Connection conn=null;
Statement stmt=null;
public xxxAdapter()
{
conn = DBConnectionPool().getConnection(); // Initilize the connection object to get the connection from pool
}
public xxxAdapter(Connection connIn)
{
conn = connIn; // Initilize the connection object with the connection object of calling class.
}
public void getName(int param1, String param2) throws Exception
{
String sql="SELECT EMP_NAME FROM EMP WHERE EMP_ID="'+param1+"' AND EMP_DEPT='"+param2+"'";
try
{
stmt= conn.createStatement(sql);
--- REST CODE GOES HERE ----
}
catch(SQLException e)
{
// Exception caught
}
finally
{
if(conn != null)
DBConnectionPool().freeConnection(conn);//return the connection to the pool
}
}
public void getDetails(String param1) throws Exception
{
String sql="SELECT * FROM EMP WHERE EMP_NAME="'+param1+"' ";
try
{
stmt= conn.createStatement(sql);
--- REST CODE GOES HERE ----
}
catch(SQLException e)
{
// Exception caught
}
finally
{
if(conn != null)
DBConnectionPool().freeConnection(conn);//return the connection to the pool
}
}
Awaiting to have your comments..
[ March 30, 2003: Message edited by: san patil ]