mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
hbase support
This commit is contained in:
@@ -15,7 +15,7 @@ public class HBaseDriver implements Driver {
|
||||
return null;
|
||||
}
|
||||
|
||||
String rest = url.substring(PREFIX.length() + 1);
|
||||
String rest = url.substring(PREFIX.length());
|
||||
|
||||
info.put("hbase.zookeeper.quorum", rest);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.sql.Statement;
|
||||
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.client.ResultScanner;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
import com.alibaba.druid.common.jdbc.ResultSetBase;
|
||||
|
||||
@@ -59,6 +60,14 @@ public class HBaseResultSet extends ResultSetBase {
|
||||
public Object getObjectInternal(int columnIndex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String columnName) throws SQLException {
|
||||
byte[] qualifier = Bytes.toBytes(columnName);
|
||||
byte[] family = Bytes.toBytes("d");
|
||||
byte[] value = result.getValue(family, qualifier);
|
||||
return Bytes.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
|
||||
@@ -11,12 +11,12 @@ import junit.framework.TestCase;
|
||||
public class HBaseDriverTest extends TestCase {
|
||||
public void test_0 () throws Exception {
|
||||
HBaseDriver driver = new HBaseDriver();
|
||||
Connection conn = driver.connect("jdbc:druid-hbase::10.20.153.63", new Properties());
|
||||
Connection conn = driver.connect("jdbc:druid-hbase:10.20.153.63", new Properties());
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM test");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
System.out.print(rs.getString("id"));
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
@@ -27,6 +27,7 @@ log4j.category.org.codehaus.xfire=INFO
|
||||
log4j.category.httpclient=INFO
|
||||
log4j.category.org.apache.struts.action.ActionServlet=ERROR
|
||||
log4j.category.com.alibaba.druid.mock=ERROR
|
||||
log4j.category.org.apache.hadoop.conf.Configuration=INFO
|
||||
log4j.category.org.apache.hadoop=WARN
|
||||
log4j.category.org.apache.zookeeper=ERROR
|
||||
|
||||
log4j.rootLogger=TRACE,CONSOLE
|
||||
|
||||
Reference in New Issue
Block a user