It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

Oralce and Java- Returning ResultSet from a Database

Oralce and Java- Returning ResultSet from a Database

Postby achilles on Wed May 16, 2007 12:35 pm

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:
Code: Select all
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:
Code: Select all
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:

Code: Select all
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?
achilles
 
Posts: 7
Joined: Thu Apr 19, 2007 3:38 pm
Location: Tehran-Iran

Who is online

Users browsing this forum: No registered users and 1 guest