function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VivoVivo 

External DB Help

Hi guys, I am very new to data integration and could really use some help.

 

One of my visualforce page requires me to query a table from an external database. I'm seeing mixed answers here and there but cannot really figure out what to do.

An example code I am supposed to base my code like uses JDBC drivers to do it such as Connection, registerDriver,getConnection and so on.

 

What is the best way to implement a simple code that queries a table from an external database? The user/pass and all that stuff is given.

 

Thanks.

 

 

Some sample code I have from another site:

DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); 
conn1 = DriverManager.getConnection(dbUrl, userName, pwd); 


stmt = conn1.createStatement();
rs = stmt.executeQuery("select username, entg_utils.getDataSourcePassword(datasource_id), datasource_url from entg_test_data_sources "+
   "where datasource_id = "+dataSource );
rs.next();
userName = rs.getString(1);
pwd = rs.getString(2);
dbUrl = rs.getString(3);
stmt.close();

 

qid = -1;
stmt = conn1.createStatement();
rs = stmt.executeQuery("select query_id from entg_test_data_queries where query_text = '"+query.replaceAll("-PERC-","+").replaceAll("-PLUS-","+").replaceAll("'","''")+"'");
if (rs.next()) 
  qid = rs.getInt(1);
stmt.close();

 conn = DriverManager.getConnection(dbUrl, userName, pwd); 
 stmt = conn.createStatement();
 rs = stmt.executeQuery(query.replaceAll("-PERC-","+").replaceAll("-PLUS-","+"));

} catch (Exception ex) {
  success=false;
  errMsg = ex.getMessage();
}

 

Vinita_SFDCVinita_SFDC

Hello,

 

salesforce.com can not connect directly to external databases. We have following options for achieving this:

1. integrate the data into salesforce.com and store the data using the Force.com Web Services API. then build your Visualforce page on that data as needed. or you could use the Data Loader to update the data. More info: http://wiki.apexdevnet.com/index.php/Data_Loader

2. web-service enable your backend data and have apex make "callouts" (web service calls) to retrieve the data. there are some constraints about request and response size so please read the Apex Documentation links below for more information.

If your web service provides a WSDL, you can try to import it to Apex and Apex will auto-generate the apex classes. More info here: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_web_services_wsdl2apex.htm

Or you can construct the web service message using the HTTP (RESTful) apex classes. More info here: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_classes_restful.htm