IBM Worklight, now part of IBM MobileFirst Platform Foundation, was a popular enterprise mobile platform for building hybrid mobile apps. One key feature was adapters, which allowed secure, structured access to backend services such as SQL databases, REST APIs, or SOAP services.
This guide on javatechig.com explains how to create a SQL adapter in IBM Worklight, step by step, and provides modern context for developers maintaining legacy systems.
Note: IBM Worklight/MobileFirst is considered legacy. For new projects, consider Spring Boot REST APIs, Node.js backend adapters, or Capacitor/Ionic with cloud databases.
What Is a SQL Adapter in IBM Worklight?
A SQL Adapter is a server-side component that:
- Connects mobile apps to relational databases (MySQL, Oracle, SQL Server)
- Executes SQL queries or stored procedures
- Returns structured JSON responses to the mobile client
- Handles security and authentication in a centralized way
Adapters allow developers to decouple mobile apps from direct database access, improving security and maintainability.
Step 1 – Set Up IBM Worklight Project
- Open IBM Worklight Studio (Eclipse-based)
- Create a new Worklight Project:
- File → New → Worklight Project
- Name:
SQLAdapterDemo
- Create an application module under the project.
Step 2 – Create a SQL Adapter
- Right-click the Adapters folder → New → SQL Adapter
- Enter adapter properties:
- Adapter Name:
EmployeeAdapter - Package:
com.javatechig.adapters - Database Type: Choose (MySQL/Oracle/SQL Server)
- Adapter Name:
- Worklight generates:
EmployeeAdapter.xml– configurationEmployeeAdapter-impl.js– procedure implementation
Step 3 – Configure Database Connection
In the generated EmployeeAdapter.xml:
<connectivity>
<connectionPolicy xsi:type="sql:SQLConnectionPolicy">
<datasource>jdbc/EmployeeDB</datasource>
<user>db_user</user>
<password>db_password</password>
<driverClass>com.mysql.jdbc.Driver</driverClass>
</connectionPolicy>
</connectivity>
datasource: JNDI or JDBC datasourcedriverClass: JDBC driveruser/password: database credentials
Modern alternative: Instead of embedded SQL adapters, use RESTful APIs backed by your SQL database.
Step 4 – Define Adapter Procedures
Procedures define server-side functions exposed to the mobile app.
EmployeeAdapter-impl.js example:
function getAllEmployees() {
var sqlStatement = "SELECT * FROM employees";
return WL.Server.invokeSQLStatement({
preparedStatement: sqlStatement,
parameters: []
});
}
WL.Server.invokeSQLStatementexecutes the query- Returns JSON array of employees
Step 5 – Deploy Adapter
- Right-click the adapter → Deploy Adapter
- Verify deployment in Worklight Console → Adapters section
- Test procedures using the Test tab
Step 6 – Invoke Adapter from Mobile App
Example JavaScript call from the mobile app:
WL.Client.invokeProcedure({
adapter: 'EmployeeAdapter',
procedure: 'getAllEmployees',
parameters: []
}, {
onSuccess: function(response) {
console.log('Employees:', response.invocationResult);
},
onFailure: function(error) {
console.error('Adapter call failed:', error);
}
});
adapter: Adapter nameprocedure: Function to callparameters: Array of parameters for SQL statements
Security Considerations
- Never expose raw SQL queries to the client
- Use Worklight security realms and authenticators
- Validate all input to prevent SQL injection
- Consider encrypting sensitive data in transit
Modern Notes & Alternatives (2026)
While Worklight adapters are still useful for legacy apps:
- For new hybrid apps, use Capacitor/Ionic or React Native
- Create backend REST APIs with Node.js, Spring Boot, or .NET Core
- Secure SQL database access via ORMs like Sequelize or Hibernate
- This approach simplifies maintenance and improves platform longevity
Summary
This guide covered:
- Setting up IBM Worklight project
- Creating a SQL adapter
- Configuring database connection
- Defining procedures
- Deploying and invoking adapters from the mobile app
- Security best practices
- Modern alternatives for 2026
Even though Worklight is legacy, understanding SQL adapters is valuable for maintaining enterprise apps and migrating to modern backend solutions.


