Skip to content

Instantly share code, notes, and snippets.

@naren-dremio
Created April 20, 2020 13:02
Show Gist options
  • Save naren-dremio/cfa0de4ad892b3768bb6e3eebb877644 to your computer and use it in GitHub Desktop.
Save naren-dremio/cfa0de4ad892b3768bb6e3eebb877644 to your computer and use it in GitHub Desktop.
JDBC example for Dremio
// Requires JDK 1.8
// Run it with:
// javac Main.java && java -cp .:dremio-jdbc-driver-4.2.1-202004111451200819-0c3ecaea.jar Main
import java.sql.*;
import java.util.Properties;
public class Main {
public static void main(String[] args) {
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";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.print(rs.getString("user"));
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
}
@naren-dremio
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment