Please see the attached file of code and let me know where can i change so
that it start working
Thanks , Kunal
On Mon, Dec 29, 2014 at 1:14 AM, Ravi Kiran <[email protected]>
wrote:
> Hi Kunal,
> Appreciate if you can show the code you have written to help you in the
> problems you are facing(if any). If you have setup Phoenix and Hadoop and
> HBase correctly , upserting values into a table is simple using the
> standard jdbc code.
>
> You can have a look at this *toy code* here
> https://gist.github.com/mravi/501fa00b942764eb0dca#file-stocksampledatagenerator-java.
>
>
> Regards
> Ravi
>
> On Sun, Dec 28, 2014 at 11:31 AM, Kunal Gupta <[email protected]>
> wrote:
>
>> Hello
>>
>> I am doing MTech From IIIT-DELHI. Recently i am working on your
>> project(Apache Phoenix) and successful in Integrating Apache Phoenix on
>> Apache HBase under Hadoop File system in Pseudo Distributed.
>>
>> I want to implemet some algorithm in 2 tier way , where one tier is a
>> JAVA application and another is your Apache phoenix connected to HBase. By
>> help of JAVA application i am successful in making connection with phoenix
>> using JDBC Driver and tried to run all DML and DDL statement after creating
>> connection but when i ran UPSERT STATEMENT query in executeUpdate()
>> function of PhoenixStatement class then without giving error it runs but
>> when i check whether the value is inserted or not then it shows me 0 rows
>> affected in table and when i ran CREATE TABLE query statement in same
>> executeUpdate() function of PhoenixStatement class then it created the
>> table in HBase.
>>
>> So please can you help me , how can i UPSERT the values into table by
>> java application.
>>
>> Please help me how can i fix it to insert all values into table through
>> JAVA APPLICATION.
>>
>> Thanks , Kunal
>>
>>
>
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import java.util.Map.Entry;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDriver;
import org.apache.phoenix.jdbc.PhoenixPreparedStatement;
import org.apache.phoenix.jdbc.PhoenixResultSet;
import org.apache.phoenix.jdbc.PhoenixStatement;
public class Casuality {
public static PhoenixDriver phoenix_driver=new PhoenixDriver();
public static Properties prop=new Properties();
public void readDataBase(ArrayList<String> relation) throws Exception {
try {
Connection conn=(Connection) phoenix_driver.connect("jdbc:phoenix:localhost",prop);
PhoenixConnection phoenix_conn=new PhoenixConnection((PhoenixConnection) conn);
PhoenixStatement phoenix_statement=new PhoenixStatement(phoenix_conn);
phoenix_statement.executeUpdate("DROP TABLE IF EXISTS CASULAITY");
phoenix_statement.executeUpdate("CREATE TABLE casulaity(eventA varchar(200),eventB varchar(200),CONSTRAINT pk PRIMARY KEY(eventA,eventB))");
for(String s:relation)
{
if(s.contains("->"))
{
PhoenixStatement phoenix_statement1=new PhoenixStatement(phoenix_conn);
String g[]=s.split("->");
phoenix_statement1.executeUpdate("UPSERT INTO CASULAITY(EVENTA,EVENTB) VALUES ('"+g[0]+"','"+g[1]+"')");
phoenix_statement1.close();
}
}
} catch (Exception e) {
throw e;
}
}
}