Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Connecting Oracle 19c ODBC using C++

User_AKR7XMay 20 2022

Hi team,
I am very new to Oracle and trying to write a hello world program to connect to the Oracle ODBC through C++ code so that I can get the connection opened and then execute my store procedure. I am using Visual Studio 2017 editor on Windows 10. This is what I am trying to achieve

#include <Windows.h> 
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
int main() {
SQLHANDLE g_sqlEnvHandle;
SQLHANDLE g_sqlConnHandle;
SQLRETURN rc;

/* Allocate the Environment Handle */
rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &g_sqlEnvHandle);
/* Set the ODBC version environment attribute */
rc = SQLSetEnvAttr(g_sqlEnvHandle, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
/* Allocate connection handle */
rc = SQLAllocHandle(SQL_HANDLE_DBC, g_sqlEnvHandle, &g_sqlConnHandle);
/* Connect to ODBC driver */
char sConnString_in[2000] = "DRIVER={Oracle in OraDB19Home1};SERVER=localhost;UID=system;PWD=abc;DATABASE=mydataBase";
rc = SQLDriverConnect(g_sqlConnHandle, NULL, (SQLCHAR*)sConnString_in, (SQLSMALLINT)lstrlen((char *)sConnString_in), sConnOut, 200, &cbConnStrOut, SQL_DRIVER_NOPROMPT);
}

On debugging the code, I am always getting -1 from SQLDriverConnect. Any help would be appreciated.
Thank.

Comments

Naveent_2785

The below is working:

use JSON.parse() on the string and stored the output in a JSON object. Send the JSON object as a request to the REST reference

mateo91

Thanks! This helps!

Demetrius Brackens

Was javascript used to implement this solution? Do you have an example? Thanks.

mateo91

You must use the Javascript component after your transform component. Then you just add the JSON.parse() call on your JSON Object variable used in the Transform (e.g. JSON.parse(<jsonObjectVariable>);)
I ended up not even needing my Transform Component since I was receiving JSON in my request. Then I just used my Javascript component to parse what I needed in the receive payload before sending it off to the external destination.

Demetrius Brackens

Thanks for your help. This is working for me now.

Hi, I am having the same parsing issue. Can you show me example of JSON.parse(<jsonObjectVariable>);

mateo91

@User_489HG - Did you get this resolved? Let me know and I can provide an example. You can do this with both a JavaScript component and an Assign Component.

Maruthi Gottumukkala

Can you please provide me examples.

Maruthi Gottumukkala

Finally I figured it out. Appreciated for the tip. Thank you so much guys.

User_FRYTH

I am having the same issue kind of issue, in OSB 12c, when using xslt and nXSDTraslate, it shows output in binary format,
Then I have used commons-codec-1.7.jar to extract the string from binary format.
Now my rest api is not accepting the request, so I need to covert it from string to json then send it to REST api.
mateo91/User_489HG , Can you please share some example, how to do that.

1552110

After you Convert your XML to String using Translate activity, Add a JavaScript activity and add $JsonInput = JSON.parse($jsonInputString) to the Code snippet to convert the String to JSON object. In the example here $JsonInput vairiable is a JSON object input for my REST service call. Hope this helps.

User_FYU9P

Thanks for help. It is working

1 - 12

Post Details

Added on May 20 2022
1 comment
1,553 views