Ready to get started?

Learn more about the or download a free trial:

Download Now

Configure the CData JDBC Driver for Sage US in a Connection Pool in Tomcat

Connect to Sage US data from a connection pool in Tomcat.

The CData JDBC Drivers support standard JDBC interfaces to integrate with Web applications running on the JVM. This article details how to connect to Sage US data from a connection pool in Tomcat.

Connect to Sage US Data through a Connection Pool in Tomcat

  1. Copy the CData JAR and CData .lic file to $CATALINA_HOME/lib. The CData JAR is located in the lib subfolder of the installation directory.
  2. Add a definition of the resource to the context. Specify the JDBC URL here.

    The Application Id and Company Name connection string options are required to connect to Sage as a data source. You can obtain an Application Id by contacting Sage directly to request access to the Sage 50 SDK.

    Sage must be installed on the machine. The Sage.Peachtree.API.dll and Sage.Peachtree.API.Resolver.dll assemblies are required. These assemblies are installed with Sage in C:\Program Files\Sage\Peachtree\API\. Additionally, the Sage SDK requires .NET Framework 4.0 and is only compatible with 32-bit applications. To use the Sage SDK in Visual Studio, set the Platform Target property to "x86" in Project -> Properties -> Build.

    You must authorize the application to access company data: To authorize your application to access Sage, restart the Sage application, open the company you want to access, and connect with your application. You will then be prompted to set access permissions for the application in the resulting dialog.

    While the compiled executable will require authorization only once, during development you may need to follow this process to reauthorize a new build. To avoid restarting the Sage application when developing with Visual Studio, click Build -> Configuration Manager and uncheck "Build" for your project.

    Built-in Connection String Designer

    For assistance in constructing the JDBC URL, use the connection string designer built into the Sage US JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

    java -jar cdata.jdbc.sage50us.jar

    Fill in the connection properties and copy the connection string to the clipboard.

    You can see the JDBC URL specified in the resource definition below.

    <Resource name="jdbc/sage50us" auth="Container" type="javax.sql.DataSource" driverClassName="cdata.jdbc.sage50us.Sage50USDriver" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" url="jdbc:sage50us:ApplicationId=8dfafu4V4ODmh1fM0xx;CompanyName=Bellwether Garden Supply - Premium;" maxActive="20" maxIdle="10" maxWait="-1" />

    To allow a single application to access Sage US data, add the code above to the context.xml in the application's META-INF directory.

    For a shared resource configuration, add the code above to the context.xml located in $CATALINA_BASE/conf. A shared resource configuration provides connectivity to Sage US for all applications.

  3. Add a reference to the resource to the web.xml for the application. Sage US data JSP jdbc/Sage50US javax.sql.DataSource Container
  4. Initialize connections from the connection pool: Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:/comp/env"); DataSource ds = (DataSource)envContext.lookup("jdbc/Sage50US"); Connection conn = ds.getConnection();

More Tomcat Integration

The steps above show how to connect to Sage US data in a simple connection pooling scenario. For more use cases and information, see the JNDI Datasource How-To in the Tomcat documentation.