Menu DEVPPL Search
160.812
MEMBERS
15.941
TOPICS
63.227
POSTS
  562
FLASH GAMES
7.717
TUTORIALS
 

Login

E-mail:
Password:

Oralce and Java- Returning ResultSet from a Database

0

Loading

Oralce and Java- Returning ResultSet from a Database

Postby Achilles » Wed May 16, 2007 1: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
 
Reputation: 0
Posts: 7
Joined: Thu Apr 19, 2007 4:38 pm
Location: Tehran-Iran
Highscores: 0
Arcade winning challenges: 0

Oralce and Java- Returning ResultSet from a Database - Sponsored results

Sponsored results

Login to get rid of ads

 

cron
^ Back to Top