Skip to content

Commit

Permalink
HBASE-23854 replaced deprecated code in Example Scala Code section
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Busbey <[email protected]>
  • Loading branch information
michelheil authored and busbey committed Feb 21, 2020
1 parent 0b2eb35 commit 400b7ce
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/main/asciidoc/_chapters/external_apis.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -934,35 +934,33 @@ libraryDependencies ++= Seq(

=== Example Scala Code

This example lists HBase tables, creates a new table, and adds a row to it.
This example lists HBase tables, creates a new table, adds a row to it, and gets the value of the row.

[source, scala]
----
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.{Connection,ConnectionFactory,HBaseAdmin,HTable,Put,Get}
import org.apache.hadoop.hbase.{HBaseConfiguration, TableName}
import org.apache.hadoop.hbase.client.{Admin, Connection, ConnectionFactory, Get, Put}
import org.apache.hadoop.hbase.util.Bytes
val conf = new HBaseConfiguration()
val conf = HBaseConfiguration.create()
val connection = ConnectionFactory.createConnection(conf);
val admin = connection.getAdmin();
// list the tables
val listtables=admin.listTables()
val listtables = admin.listTables()
listtables.foreach(println)
// let's insert some data in 'mytable' and get the row
val table = connection.getTable(TableName.valueOf("mytable"))
val table = new HTable(conf, "mytable")
val theput= new Put(Bytes.toBytes("rowkey1"))
val theput = new Put(Bytes.toBytes("rowkey1"))
theput.add(Bytes.toBytes("ids"),Bytes.toBytes("id1"),Bytes.toBytes("one"))
theput.addColumn(Bytes.toBytes("ids"),Bytes.toBytes("id1"),Bytes.toBytes("one"))
table.put(theput)
val theget= new Get(Bytes.toBytes("rowkey1"))
val result=table.get(theget)
val value=result.value()
val theget = new Get(Bytes.toBytes("rowkey1"))
val result = table.get(theget)
val value = result.value()
println(Bytes.toString(value))
----

Expand Down

0 comments on commit 400b7ce

Please sign in to comment.