Jump to content

JDBC connection using .jar driver


Jewtus
 Share

Recommended Posts

I've previously been using a connection to a db2 database using ODBC connections and the IBM DB2 driver.

$sqlCon = ObjCreate("ADODB.Connection")
$sqlCon.Mode = 16  ; shared
$sqlCon.CursorLocation = 3 ; client side cursor
$sqlCon.Open ("DSN="&$DSN&";UID="&$UserID&";Password="&$Pass&";Database="&$database&";Port="&$port&";Hostname="&$Hostname&";")
If @error Then
    MsgBox(0, "ERROR", "Failed to connect to the DB2 database")
    Exit
EndIf

I'm wondering if there is a way to package this all into my script.

I've located the db2jcc4.jar and the license files, but I'm not sure how to configure this with autoit.

I was playing around with a script I found >HERE but when I tweak it, it throws a com error...

$sqlCon = ObjCreate("ADODB.Connection")
$sqlCon.Mode = 16  ; shared
$sqlCon.CursorLocation = 3 ; client side cursor
$sqlCon.Open ("Driver=jdbc:db2://"&$hostname&":"&$port&"/"&$Database&"; UID="&$userID&"; PWD="&$Pass&";")
If @error Then
    MsgBox(0, "ERROR", "Failed to connect to the DB2 database")
    Exit
EndIf

I found an article here that talks about changing the CLASSPATH for the session by doing:

java -classpath <dir>\db2jcc4.jar

but when I try to run that via the command line (to see if it will work), it just outputs the usage command

Usage: java [-options] class [args...]

I'm obviously missing something here. Does anyone know how to make this work? Some other threads I read here say that you cannot do it with COM objects (), but if I can do it via ODBC, I don't understand why I couldn't use JDBC. Anyone able to shed some light on this subject?

 

Link to comment
Share on other sites

I'd be fairly surprised if you can make an ADO connection work with a JDBC driver.  JDBC is pretty Java specific. 

 

Having said that, the "-classpath" function that you typed does not alter the session classpath, it alters the classpath for that one specific call to java.exe .

E.g.:

java -classpath %CLASSPATH%;C:SomeDirectoryIWantToAdd MyJavaClass

That sets classpath to the current classpath plus the example directory I added, and then attempts to start "MyJavaClass" (which in this case would end with .class and be in the default package).  It does that for the one specific call to the runtime engine.  No other programs will know about that classpath, and if you were to run the program again, you'd need to add the classpath again, it wouldn't even survive until the next call to the same place.

 

You can set a classpath environment variable to try your connection.  Just set it using "set".  E.g.:

set CLASSPATH=%CLASSPATH%;<dir>db2jcc4.jar

 

I seriously doubt if that will work with your AutoIt code though.

Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

Thank you for clarifying the classpath.

Do you know if there IS a way to invoke the JDBC with autoit? The tool I'm currently using to connect to DB2 is DBeaver, which is open source. I'm trying to avoid downloading the source code and trying to reverse engineer how they are able to invoke the JDBC connection.

Link to comment
Share on other sites

I've never heard of jdbc being used by anything else than java.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Yes, which means I might need to make a java plugin to invoke it via autoit (essentially build a java script that I can call from autoit via command line and then read back the results into autoit). Ideally, I'd use web services, but when you have lemons... 

I was just curious if anyone had already done this or if they knew of any tools that I could use rather then reverse engineering a java application for a single part of the code. If I get it worked out, I'll upload it somewhere so others can use it (It appears that are a few DB2 users on these boards using Oracle or IBM db2 connections). I just wish a special driver wasn't required to connect to these databases...

Link to comment
Share on other sites

  • 2 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...