Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,

Thanks again for your contribution for helping other developers.

I am new in Android development. I am working in vb.net for a long time so I am comfortable with it. In that environment I am used to use a Function for getting the DataTable or DataRow in the following way:
VB.NET
Public Function getSQLDT(ByVal SQLString As String) As DataTable
        Dim RowsAffected as Integer = 0
        strErrorMessage = "";
        Dim dataTable As DataTable = New DataTable
        Dim OracleDA As OracleDataAdapter = New OracleDataAdapter
        Try
                OracleConObject = New OracleConnection(ConectionString)
                OracleConObject.Open()
                OracleDA.SelectCommand = BuildSQL(SQLString)
      OracleTransObj = OracleConObject.BeginTransaction(IsolationLevel.ReadCommitted)
                    boolTransactionAlreadyOn = True
                End If
                OracleDA.SelectCommand = BuildQueryCommandWithSQL(SQLString)
            End If
            OracleDA.Fill(dataTable)
            Return dataTable
        Catch ex As Exception
            strErrorMessage = "Error"+ ex.Message
            Return Nothing
        Finally
            If Not boolTransactionRequired Then
                If Not IsNothing(OracleConObject) Then
                    OracleConObject.Close()
                    OracleConObject.Dispose()
                    OracleConObject = Nothing
                End If
            End If
            OracleDA.Dispose()
            OracleDA = Nothing
        End Try
    End Function


VB.NET
Private Function BuildSQL(ByVal SQLString As String) As OracleCommand
        Dim objCmd As OracleCommand = New OracleCommand(SQLString, OracleConObject)
        objCmd.CommandType = CommandType.Text
        Return objCmd
    End Function


Basically I am passing a SQL String (Eg: "Select * from scott.emp") and the function return me all the rows in the form of DataTable.

So now I am trying to achieve the same thing in the Android Application. Here I want to pass a Sql String only through my activity or fragment and all the database related activity will be done in separate class and functions on that class will return TextView or EditText or Image.
Basically I want to segregate the Business logic code and Database related code and furthermore in this approach I have to write the Database related code only for once and can reuse in any application any time.

So my question is is this possible only through Android coding. Please do not tell me that I have to develop a web service or PHP coding for this Job. I want to learn all this by Java only. I am a new student of Java.

Please help me in this regard. Any reply id highly solicited.
Thanking you
Tanmoy
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900