Connecting to Database

Visual COBOL

Brings the productivity of modern, industry-leading Integrated Development Environments (IDEs) to COBOL – including deploying key business-critical COBOL applications to Windows 7, .NET, JVM and the cloud.

Connecting to Database

This question is answered

Hi

I am using visual COBOL for Eclipse, I want to know exactly ho to connect to mysql or oracle database and start using

EXEC SQL statement using native cobol

best regards

Verified Answer
  • If you wish to connect to a mySQL database in native code then you will need to set up an ODBC DSN for the connection using one of the ODBC Administrator tools.

    If your program will be 32-bit (default) then you need to start the 32-bit version of ODBC Administrator.
    Navigate to Start Menu-->All Programs-->Micro Focus Visual COBOL-->Data Tools-->Data Connections-->ODBC Data Source Administrator 32-bit.

    Likewise if you are compiling to 64-bit (P64 directive) then you need to start the 64-bit version of ODBC Administrator.
    Navigate to Start Menu-->All Programs-->Micro Focus Visual COBOL-->Data Tools-->Data Connections-->ODBC Data Source Administrator 64-bit.

    Under System DSN click Add and then select the mySQL Driver from the list of available drivers.
    The name that you give to the DSN will be the name that you use in the EXEC SQL CONNECT statement.
    You will also have to give it the name of the mySQL database to connect to.

    Other parameters lke user and password can be specified in the DSN or can be omitted and passed in as part of the EXEC SQL CONNECT statement.
    I would suggest that you place the user and password in the DSN now so that you can click on the test connect button to ensure that the DSN is setup properly.

    Once the DSN is setup you can try your program.

    Since mySQL uses ODBC then you would set the OpenESQL directive:
         SQL(DBMAN=ODBC)

    You can set this directly in the source by adding:
         $SET SQL(DBMAN=ODBC)
    to the top of the program starting in column 7 or by adding it to the project by right-clicking on project name-->Properties-->Micro Focus COBOL-->Build Configurations-->COBOL-->SQL Settings:

    Your Connect statement can be as simple as:

    EXEC SQL CONNECT TO MYSQLDSN END-EXEC

    Where MYSQLDSN is the name that you gave to the DSN in the ODBC Administrator.

    Open up the Samples browser and click SQL in the column on left.
    Then from the right hand column select CONNECT which is a sample program that demonstrates the various methods that can be uses to connect to a database using OpenESQL.

    Thanks.

All Replies
  • You can connect to mysql using the OpenESQL Technology which allows you to code EXEC SQL statements that will be converted into ODBC commands that will be sent to your mysql ODBC driver.

    For Oracle you have a couple of choices.

    You can use the OpenESQL Technology if you wish to use an Oracle ODBC driver or you can use the Oracle Pro*COBOL product (Oracle tool) and use the Visual COBOL COBSQL Technology to interface with Pro*COBOL.

    All of these options are documented here:

     

    I suggest that you read through this material in order to get a better understanding of these options.

    You can also open up the Visual COBOL Samples Browser from Start Menu-->All Programs-->Micro Focus Visual COBOL-->Samples and click on SQL in the left hand column and then choose from the list of native SQL samples in the right hand column.

    Thanks.

     

  • Hi :)

    Unfortunately it didn't work, I need to know how to exactly connect to MySQL database in native COBOL and how to specify the database name and log in credentials ?? and any other config if necessary

    best regards

  • If you wish to connect to a mySQL database in native code then you will need to set up an ODBC DSN for the connection using one of the ODBC Administrator tools.

    If your program will be 32-bit (default) then you need to start the 32-bit version of ODBC Administrator.
    Navigate to Start Menu-->All Programs-->Micro Focus Visual COBOL-->Data Tools-->Data Connections-->ODBC Data Source Administrator 32-bit.

    Likewise if you are compiling to 64-bit (P64 directive) then you need to start the 64-bit version of ODBC Administrator.
    Navigate to Start Menu-->All Programs-->Micro Focus Visual COBOL-->Data Tools-->Data Connections-->ODBC Data Source Administrator 64-bit.

    Under System DSN click Add and then select the mySQL Driver from the list of available drivers.
    The name that you give to the DSN will be the name that you use in the EXEC SQL CONNECT statement.
    You will also have to give it the name of the mySQL database to connect to.

    Other parameters lke user and password can be specified in the DSN or can be omitted and passed in as part of the EXEC SQL CONNECT statement.
    I would suggest that you place the user and password in the DSN now so that you can click on the test connect button to ensure that the DSN is setup properly.

    Once the DSN is setup you can try your program.

    Since mySQL uses ODBC then you would set the OpenESQL directive:
         SQL(DBMAN=ODBC)

    You can set this directly in the source by adding:
         $SET SQL(DBMAN=ODBC)
    to the top of the program starting in column 7 or by adding it to the project by right-clicking on project name-->Properties-->Micro Focus COBOL-->Build Configurations-->COBOL-->SQL Settings:

    Your Connect statement can be as simple as:

    EXEC SQL CONNECT TO MYSQLDSN END-EXEC

    Where MYSQLDSN is the name that you gave to the DSN in the ODBC Administrator.

    Open up the Samples browser and click SQL in the column on left.
    Then from the right hand column select CONNECT which is a sample program that demonstrates the various methods that can be uses to connect to a database using OpenESQL.

    Thanks.