NATO Posted November 8, 2007 Share Posted November 8, 2007 Hi, has anybody had any luck in connecting to DB2 or Apache's Derby databases? I've seen the MySQL, MS SQL, and Access data sources covered, but I'm currently living in a Java world and would love to find a UDF for DB2 connectivity! Link to comment Share on other sites More sharing options...
ptrex Posted November 9, 2007 Share Posted November 9, 2007 @NATO I don't have a DB2 (AS400 or simular around) but this should get you going. expandcollapse popup; Initialize COM error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $sqlCon = ObjCreate("ADODB.Connection") $sqlCon.Mode = 16 ; shared $sqlCon.CursorLocation = 3 ; client side cursor ; http://ns7.webmasters.com/caspdoc/html/syntax_for_dsn_less_connection_strings.htm ; where [ip_address] is the IP address of the database server, [port_number] is the port for the database server, ; [database_name] is the name of the database, ; and [username] and [password] are the username and password required for accessing the database. $sqlCon.Open ("Driver={DB2}; IP=[ip_address]; Port=[port_number]; Database=[database_name]; UID=[username]; PWD=[password]") If @error Then MsgBox(0, "ERROR", "Failed to connect to the database") Exit EndIf ; See also Catalog "ADOX Catalog Example.au3" $sqlRs = ObjCreate("ADODB.Recordset") If Not @error Then $sqlRs.open ("select * from Table", $sqlCon) If Not @error Then ;Loop until the end of file While Not $sqlRs.EOF ;Retrieve data from the following fields $OptionName = $sqlRs.Fields ('name' ).Value $OptionVal = $sqlRs.Fields ('value' ).Value MsgBox(0, "Record Found", "Name: " & $OptionName & @CRLF & "Value: " & $OptionVal) $sqlRs.FIELDS('"' & $OptionName & '"') = ".F." ; ADDED THIS LINE ; $sqlRs.Update ; ADDED THIS LINE $sqlRs.MoveNext WEnd $sqlRs.close EndIf EndIf Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"COM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfunc Regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
NATO Posted November 10, 2007 Author Share Posted November 10, 2007 Thanks! Unfortunately, it's only throwing a COM error and stating that the data source name not found and no driver specified. I think the ODBC/CLI driver from IBM is cryptic at best. I'll work on it awhile and see what I can contribute to the community should anybody else be forced into using DB2. If you are *really* bored, you can download a free version of DB2 to play with from IBM--or use Derby from Apache since it is pretty similar, but with less overhead. Cheers, Nate Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now