Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Databas closing issue (http://www.velocityreviews.com/forums/t544547-databas-closing-issue.html)

francan00@yahoo.com 10-16-2007 04:07 AM

Databas closing issue
 
I have a method that inserts data into my Oracle 9i database with no
problems or Database closing issues:

CODE
public class MainClass
{

public PreparedStatement preparer;
public Connection connection;

public MainClass()
{
connection = new DbConnectionClass().getConnection();
}

public int inserter(Beann abc)
{
int dat = 0;
try
{
preparer = connection.prepareStatement("insert into abTable
(one,two) values (?,?)");
preparer.setString(1, abc.getOne());
preparer.setString(2, abc.getTwo());
preparer.executeUpdate();
}
catch(Exception e)
{
e.printStackTrace();
}
return dat;
}

public int matcher(Beann abc)
{
try
{
inserter(abc);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
//close the ResultSet ....
//close the Statement ....
//close the Connection ....
}
}

Now when I put the method (inserter) in another class called
OtherClass, it does insert the data but now I have database closing
issues:


CODE
public class OtherClass
{
....
public int inserter(Beann abc)
{
int dat = 0;
try
{
preparer = connection.prepareStatement("insert into abTable
(one,two) values (?,?)");
preparer.setString(1, abc.getOne());
preparer.setString(2, abc.getTwo());
preparer.executeUpdate();
}
catch(Exception e)
{
e.printStackTrace();
}
return dat;
}
.....



CODE
public class MainClass
{

public PreparedStatement preparer;
public Connection connection;

public MainClass()
{
connection = new DbConnectionClass().getConnection();
}

public int matcher(Beann abc)
{
try
{
new OtherClass().insert(abc);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
//close the ResultSet ....
//close the Statement ....
//close the Connection ....
}

In Oracle SQL Plus database resource check I see JDBC Thin Client is
opened and not closed after each insert with the above attempt.
This didnt happen when I had the method in the same class.

Please advise.



All times are GMT. The time now is 04:34 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.