hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neuron005 <neuron...@gmail.com>
Subject Trouble with Boolean,integer and timestamp
Date Wed, 21 Dec 2011 13:52:42 GMT

Hiii there
I am new to hbase and trying to explore it. I am trying to store some values
to hbase using my java program. Though I can easily store string values and
retrieve them but I am having trouble with Boolean int and timestamp.
Boolean --- whatever number I save between 0 to 9 it results in true

int -- does not let me store a number less than 3 digits and if i store a
number of 4 or 5 digits it results in different value

timestamp: How can I get timestamp from hbase for a particular column so
that I can apply toString() method on it to get in format yyyy:mm:dd
Here is my sample program of java with which I am trying
--------------------------------Please add necessary jars to
classpath(hbql,hadoop-core,hbase,commons,antlr,zookeeper,log4j)
import java.sql.*;
import java.util.Date;
public class test
{
public static void main(String args[])
{
Connection con=null;
Statement stmt = null;
	try{
		Class.forName("org.apache.hadoop.hbase.jdbc.Driver");
		con = DriverManager.getConnection("jdbc:hbql");
	stmt=con.createStatement();
    stmt.execute("CREATE TABLE Activity (f1()) IF NOT
tableexists('Activity')");

    stmt.execute("CREATE TEMP MAPPING scho8 FOR TABLE Activity"
                 + "("
                 + "keyval key, "
                 + "f1 ("
                 + "User string alias User, "
                 + " date DATE alias date, "
                + " count INTEGER alias count, "
                + " flag boolean alias flag "
                 + ") "
                 + ")");
    
    ResultSet rs = stmt.executeQuery("select * from scho8");
    System.out.println("hii there");
    while (rs.next()) {
      	System.out.println("hii there you");
        String user=rs.getString("User");
        Date feedDate=rs.getDate("date");
    	Timestamp timestamp=rs.getTimestamp("date");
    	int comment = rs.getInt("count");
    	
    	boolean flag=rs.getBoolean("flag");
    	
    	System.out.println("user is : "+ user);
    	
    	System.out.print("feed Date is :"+feedDate);
        System.out.println("Timestamp received is"+timestamp);
        System.out.println("Comment count is: " + comment);
        System.out.println("Flag is: "+flag);
        System.out.print("feed Date is :"+timestamp.toString());
    }
   rs.close();
    stmt.close();
    con.close();
	}catch(Exception e)
	{
		e.printStackTrace();
	}
}
}



-- 
View this message in context: http://old.nabble.com/Trouble-with-Boolean%2Cinteger-and-timestamp-tp33016853p33016853.html
Sent from the HBase User mailing list archive at Nabble.com.


Mime
View raw message