Skip to content

Instantly share code, notes, and snippets.

@narendrans
Last active May 30, 2023 10:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save narendrans/550860550fcebb3da1040aeb5ff31458 to your computer and use it in GitHub Desktop.
Save narendrans/550860550fcebb3da1040aeb5ff31458 to your computer and use it in GitHub Desktop.
Dremio JDBC example
// Requires JDK 1.8
// Run it with:
// javac Main.java && java -cp .:dremio-jdbc-driver-20.0.0-202201050826310141-8cc7162b.jar Main
// If the output in terminal shows the following then the test is successful.
// Printing the result
// -------------------
// User: dremio
// -------------------
import java.sql.*;
import java.util.Properties;
public class Main {
public static void main(String[] args) {
// For Dremio Cloud, the string, user & password would be as follows. Doc: https://docs.dremio.com/cloud/client-applications/jdbc/
// final String DB_URL = "jdbc:dremio:direct=sql.dremio.cloud:443;ssl=true;PROJECT_ID=<PROJECT_ID>;";
// final String USER = "$token";
// final String PASS = "<PAT TOKEN>";
final String DB_URL = "jdbc:dremio:direct=localhost:31010;";
final String USER = "dremio";
final String PASS = "dremio123";
Properties props = new Properties();
props.setProperty("user",USER);
props.setProperty("password",PASS);
Connection conn = null;
Statement stmt = null;
try {
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL, props);
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = "SELECT user";
System.out.println("Executing statement...");
ResultSet rs = stmt.executeQuery(sql);
System.out.print("Printing the result\n");
System.out.print("-------------------\n");
while (rs.next()) {
System.out.print("User: " + rs.getString("user") + "\n");
}
System.out.print("-------------------\n");
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment