- Apache Tajo - Custom Functions
- Apache Tajo - JDBC Interface
- OpenStack Swift Integration
- Apache Tajo - Integration with Hive
- Integration with HBase
- Apache Tajo - Storage Plugins
- Apache Tajo - SQL Queries
- Aggregate & Window Functions
- Apache Tajo - SQL Statements
- Apache Tajo - Table Management
- Apache Tajo - Database Creation
- Apache Tajo - JSON Functions
- Apache Tajo - DateTime Functions
- Apache Tajo - String Functions
- Apache Tajo - Math Functions
- Apache Tajo - SQL Functions
- Apache Tajo - Operators
- Apache Tajo - Data Types
- Apache Tajo - Shell Commands
- Apache Tajo - Configuration Settings
- Apache Tajo - Installation
- Apache Tajo - Architecture
- Apache Tajo - Introduction
- Apache Tajo - Home
Apache Tajo Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apache Tajo - JDBC Interface
Apache Tajo provides JDBC interface to connect and execute queries. We can use the same JDBC interface to connect Tajo from our Java based apppcation. Let us now understand how to connect Tajo and execute the commands in our sample Java apppcation using JDBC interface in this section.
Download JDBC Driver
Download the JDBC driver by visiting the following pnk −
.Now, “tajo-jdbc-0.11.3.jar” file has been downloaded on your machine.
Set Class Path
To make use of the JDBC driver in your program, set the class path as follows −
CLASSPATH = path/to/tajo-jdbc-0.11.3.jar:$CLASSPATH
Connect to Tajo
Apache Tajo provides a JDBC driver as a single jar file and it is available @ /path/to/tajo/share/jdbc-dist/tajo-jdbc-0.11.3.jar.
The connection string to connect the Apache Tajo is of the following format −
jdbc:tajo://host/ jdbc:tajo://host/database jdbc:tajo://host:port/ jdbc:tajo://host:port/database
Here,
host − The hostname of the TajoMaster.
port − The port number that server is pstening. Default port number is 26002.
database − The database name. The default database name is default.
Java Apppcation
Let us now understand Java apppcation.
Coding
import java.sql.*; import org.apache.tajo.jdbc.TajoDriver; pubpc class TajoJdbcSample { pubpc static void main(String[] args) { Connection connection = null; Statement statement = null; try { Class.forName("org.apache.tajo.jdbc.TajoDriver"); connection = DriverManager.getConnection(“jdbc:tajo://localhost/default"); statement = connection.createStatement(); String sql; sql = "select * from mytable”; // fetch records from mytable. ResultSet resultSet = statement.executeQuery(sql); while(resultSet.next()){ int id = resultSet.getInt("id"); String name = resultSet.getString("name"); System.out.print("ID: " + id + "; Name: " + name + " "); } resultSet.close(); statement.close(); connection.close(); }catch(SQLException sqlException){ sqlException.printStackTrace(); }catch(Exception exception){ exception.printStackTrace(); } } }
The apppcation can be compiled and run using the following commands.
Compilation
javac -cp /path/to/tajo-jdbc-0.11.3.jar:. TajoJdbcSample.java
Execution
java -cp /path/to/tajo-jdbc-0.11.3.jar:. TajoJdbcSample
Result
The above commands will generate the following result −
ID: 1; Name: Adam ID: 2; Name: Amit ID: 3; Name: Bob ID: 4; Name: David ID: 5; Name: Esha ID: 6; Name: Ganga ID: 7; Name: Jack ID: 8; Name: Leena ID: 9; Name: Mary ID: 10; Name: PeterAdvertisements