Saturday, 19 July 2008

More Oracle and REALBasic using MBS and Java

I have managed to get REALbasic talking to Oracle via the Java classes enabled by the MBS Java Plug In.

It was quite straightforward in the end, the code is shown below:

'Requires the Oracle Java Driver Resident in the Program Directory
'Requires the MBS REALbasic Java Plugin.rbx to be in the Plugins Directory
'Requires the MBS REALbasic Main Plugin.rbx to be in the Plugins Directory

'This Function Should be Called as Follows:

dim j as JavaDatabaseMBS
dim r as JavaRecordSetMBS
dim f as FolderItem


j=new JavaDatabaseMBS(f,"oracle.jdbc.driver.OracleDriver")
j.UserName = strUserName
j.Password = strPassWord

if j.Connect then
mCodebaseStd.DisplayInformationMessage("Successfully Connected to Oracle ...")
mCodebaseStd.DisplayStopMessage("Could Not Connect to Oracle ..."+EndOfLine+"Error Message: "+j.ErrorString+EndOfLine+"Error Code: "+str(j.Errorcode))
end i

The Oracle Java driver can be found in the /jdbc/lib directory of your ORACLE installation. This can be copied, and I have put it in the client application directory. The MBS Plugins need to be inside the Plugins directory of your REALbasic installation. The comments at the top of the method show how this method should be called to get a successful connection to Oracle, three parameters are needed, ORACLESID, UserName and Password.

The methods referred to when j.Connect is called are my own custom methods for displaying dialogs to the screen. They can be replaced by standard MsgBox calls.

My next challenge is seeing how powerful and reliable it is to access Oracle from REALbasic using these classes and Plug Ins :-)

"If you limit your choices only to what seems possible or reasonable, you disconnect yourself from what you truly want, and all that is left is a compromise." - Robert Fritz
Honest Expert Independent Technology Advice for Business

No comments: