Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

Introduction

This sample demonstrates how to use databases and database users created through WSO2 Storage Server, in a typical Java application that accesses a database via JDBC.

Building sample application

  1. Extract the JDBC URL of the created database. 
  2. Set the user name and the password of a user who is attached to the database.
  3. Select appropriate JDBC Driver class based on the backend RDBMS.

    Connection connection = null;
    
    String driverClass = "com.mysql.jdbc.Driver";
    String dbUser =  "user123";
    String dbPassword = "user123";
    String jdbcUrl = "jdbc:mysql://localhost:3306/testDB";
    
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driverClass);
    ds.setUrl(jdbcUrl);
    ds.setUsername(dbUser);
    ds.setPassword(dbPassword);
    
    try {
        connection = ds.getConnection(); 
        //your code goes here
    } catch (SQLException e) {
       log.error(e);
    } finally {
       try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            log.error(e);
        }
    }

 

  • No labels