JOIN DEVPPL

It looks like you are new here. If you want to get involved, click on Join below!



Re: Oralce and Java- Returning ResultSet from a Database

This post is from the topic: Oralce and Java- Returning ResultSet from a Database





E

keyboard_arrow_up
0
keyboard_arrow_down


Post #27331 Mark as Spam Earnshaw24
Posts: 2 - Registered: 2005-09-01 10:47:07

Hello,

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){
try{
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
con.Open()
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?



JOIN DEVPPL

It looks like you are new here. If you want to get involved, click on Join below!




MENU
Advertising