Post #27331

27331 achilles
Registered: 2007-04-19 - Posts: 7


I'm using the Tiers to Insert, Update, Delete and Select, into and from an Oracle table.
I have a provider class that has all he necessary methods to insert, update and delete.
Something like this:

public void Delete_membership (String Username){
conn=(OracleConnection) ds.getConnection (dbUser,dbPwd);
cstmt=(CallableStatement) conn.prepareCall ("{call SP_DELETE_MEMBERSHIP(?)}");
cstmt.setString (1, Username);
cstmt.execute ();
conn.close ();
} catch (Exception ex){
System.out.println (ex.getMessage ());
ex.printStackTrace ();


When writing the code in .Net, I'll have two classes (Miner and Finder) to Select data from an SQL Server Table and populate the records into collections and table classes. Inside the miner example:

Function GetLoginHistory(ByVal Id As Int32) As SqlDataReader
Dim con As New SqlConnection(cs)
Dim cmd As New SqlCommand("GetLoginHistory", con)
cmd.Parameters.Add("@id_1", SqlDbType.bigint).Value = id
cmd.CommandType = CommandType.StoredProcedure
return cmd.ExecuteReader(CommandBehavior.CloseConnection)

End Function

Then Inside the Finder, There'll be code to populate this SqlDataReader into my Collections:

Private dm as New Miner

Public Function GetLoginHistory() As LoginHistoryCollection
Dim drd As SqlDataReader = dm.GetLoginHistory()
Dim lc As New LoginHistoryCollection
PopulateLoginHistory(drd, lc)
Return lc

End Function

one the main concepts here is:

The Connection to SQL Server will be closed Automatically and the SqlDataReader will be populated into the collection. Pay Attention to the RETURN line in the MINER class' function. (CommandBehavior.CloseConnection)

Is there any way to do this in Java?