JDBC

JDBC API supports the retrieving of records from datasource by using SQL query. In order to do that, some basic jar files are required in the project. The files required are:

Example 8.1. Retrieve Records From Selected Column

When trying to retrieve records from a selected column of a datasource, you can use the following example:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class SelectSpecificColumn {
  public static void main(String[] args) throws Exception
    {
      Class<?> cls = Class.forName("com.elixirtech.jdbc.Driver");
		
      Properties props = new Properties();
      props.put("user","admin");
      props.put("password","sa");
      Connection conn = DriverManager.getConnection
  ("jdbc:repertoire://localhost:8080/",props);
      Statement s = conn.createStatement();
      ResultSet rs = s.executeQuery("SELECT Company, 2000 FROM 
  /ElixirSamples/DataSource/FruitSales.ds");
      while (rs.next())
      {
        String company = rs.getString("Company");
        float val2000 = rs.getFloat("2000");
        System.out.println("-> " + company + " " + val2000);
      }
      s.close();
      conn.close();
	}
}

If the server is not running on a local machine, change localhost to the IP address of the machine that is running the server. The API allows other SQL query commands like WHERE, AND and many others.