Skip to content

Instantly share code, notes, and snippets.

@ebuildy
Created January 7, 2016 07:42
Show Gist options
  • Save ebuildy/e0dbdaa463e07576043c to your computer and use it in GitHub Desktop.
Save ebuildy/e0dbdaa463e07576043c to your computer and use it in GitHub Desktop.
import com.zaxxer.hikari.HikariDataSource;
import org.apache.hadoop.hbase.thrift.generated.BatchMutation;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class Test
{
private Connection connection;
public static void main(String [] args)
{
HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl("jdbc:phoenix:zookeeper");
ds.setDriverClassName("org.apache.phoenix.jdbc.PhoenixDriver");
ds.setAutoCommit(false);
try {
this.connection = ds.getConnection();
System.out.println("Connection is valid: " + this.connection.isValid(10));
}
catch(SQLException e)
{
e.printStackTrace();
}
try {
PreparedStatement statement = this.connection.prepareStatement("UPSERT INTO \"events\"(\"uuid\",\"event\") VALUES(?, ?)");
statement.setString(1, "toto");
statement.setString(2, "click");
statement.executeUpdate();
this.connection.commit();
this.connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment