JDBC Driver for WordPress

Build 22.0.8462

Establishing a Connection

Creating a JDBC Data Source

You can create a JDBC data source to connect from your Java application. Creating a JDBC data source based on the CData JDBC Driver for WordPress consists of three basic steps:

  • Add the driver JAR file to the classpath. The JAR file is located in the lib subfolder of the installation directory. Note that the .lic file must be located in the same folder as the JAR file.
  • Provide the driver class. For example:
    cdata.jdbc.wordpress.WordpressDriver
  • Provide the JDBC URL. For example:
    jdbc:wordpress:URL=http://www.yourwordpresshost.com;User=yourUsername;Password=yourPassword;
    
    or
    
    jdbc:cdata:wordpress:URL=http://www.yourwordpresshost.com;User=yourUsername;Password=yourPassword;

    The second format above can be used whenever there is a conflict in your application between drivers using the same URL format to ensure you are using the CData driver. The URL must start with either "jdbc:wordpress:" or "jdbc:cdata:wordpress:" and can include any of the connection properties in name-value pairs separated with semicolons.

Connecting to WordPress

Note: For now, only connecting to self hosted wordpress instances is supported by CData JDBC Driver for WordPress.

To connect to data, set the Url and provide authentication. You must set the URL to your wordpress site, otherwise an error will be thrown indicating that the site was not found.
For example, if your site is hosted in 'http://localhost/wp/wordpress', the URL should be 'http://localhost/wp/wordpress' and not 'htpp://localhost' .

Authenticating to WordPress

WordPress uses Basic or OAuth2.0 authentication.

Basic

Basic authentication is recommended for a testing environment only.

Configure Access to WordPress

  1. Go to your WordPress host and login with your admin credentials when prompted.
  2. Make sure your WordPress supports the REST API. Wordpress 4.7 and later support it natively, earlier versions will need to install the REST API plugin.
  3. Install an authentication plugin such as Basic Authentication to secure access to the REST API.
  4. To create custom taxonomies, you need to install the Simple Taxonomy Refreshed

    Alternatively, to install the plugins manually, extract the compressed folders to the wp-content\plugins folder and then enable the plugins via the WordPress admin interface.

After setting the following connection properties, you are ready to connect:

  • AuthScheme Set this to Basic.
  • Url: Set this to your WordPress URL.
  • User: Set this to your username.
  • Password: Set this to your password.

OAuth 2.0

You can use OAuth to authenticate with WordPress.OAuth requires the authenticating user to interact with WordPress using the browser. Set AuthScheme to OAuth while using OAuth Authentication. See Using OAuth Authentication for an authentication guide.

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462