Note that there are some explanatory texts on larger screens.

plurals
  1. POread the data from hbase and insert into postgres
    primarykey
    data
    text
    <p>I am using HBase to store the data but later to suit my requirements I want to export the data from HBase to RDBM like mysql or postgres. how can i do it? i tryied by this way but canot find solution. please help me.</p> <p>this my sample code:</p> <pre><code>/** my HbaseRawDataReader class **/ public class HbaseRawDataReader { List&lt;KeyValue&gt; list = new ArrayList&lt;KeyValue&gt;(); static Configuration config = HBaseConfiguration.create(); public RadarTrack insertDBvo=new RadarTrack();// pojo class public static void main(String args[]) { HbaseRawDataReader hr=new HbaseRawDataReader(); // hr.getAllRecord(key, value); } public void getAllRecord () { try{ // This instantiates an HTable object that connects you to the table trackrecord_table HTable table = new HTable(config, "trackrecord_table"); Scan s = new Scan(); s.addColumn(Bytes.toBytes("radar"), Bytes.toBytes("IpAdderss")); s.addColumn(Bytes.toBytes("radar"), Bytes.toBytes("Trackid")); s.addColumn(Bytes.toBytes("radar"), Bytes.toBytes("Latitude")); s.addColumn(Bytes.toBytes("radar"), Bytes.toBytes("Longitude")); s.addColumn(Bytes.toBytes("radar"), Bytes.toBytes("Velocity")); s.addColumn(Bytes.toBytes("radar"), Bytes.toBytes("Course")); ResultScanner rs = table.getScanner(s); for(Result r:rs){ for(KeyValue vo : r.raw()){ // System.out.print(new String(vo.getRow()) + " "); // System.out.print(new String(vo.getFamily()) + ":"); // System.out.print(new String(vo.getQualifier()) + " "); // System.out.print(vo.getTimestamp() + " "); // System.out.println(new String(vo.getValue())); String IPAddress = vo.getQualifier().toString(); String track_ID = vo.getQualifier().toString(); String latitude = vo.getQualifier().toString(); String longitude = vo.getQualifier().toString(); String sog = vo.getQualifier().toString(); String cog = vo.getQualifier().toString(); insertDBvo.setDirection(Double.parseDouble(cog)); insertDBvo.setIpAddress(IPAddress); insertDBvo.setLatitude(latitude); insertDBvo.setLongitude(longitude); insertDBvo.setVelocity(Double.parseDouble(sog)); insertDBvo.setTrackId(Integer.parseInt(track_ID)); CsdssDAOImpl.getInstance().insertToDB(insertDBvo); } } } catch (IOException e){ e.printStackTrace(); } } } /** for postgres connection***/ public class ConnectionUtil { static Properties properties = new Properties(); static Connection connection = null; public static Connection getConncection() { if(null==connection){ // if(properties.isEmpty()){ try { properties.load(ConnectionUtil.class.getClassLoader() .getResourceAsStream("radar.properties")); } catch (IOException e) { e.printStackTrace(); } // } String driverName = properties.getProperty("drivers"); String url = properties.getProperty("url"); String userName = properties.getProperty("userName"); String password = properties.getProperty("password"); // Connection connection = null; try { // DriverManager // driverManager=(DriverManager)Class.forName(properties.getProperty("driverName")).newInstance(); Class.forName(driverName); connection = DriverManager.getConnection(url, userName, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } return connection; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload