Two methods, one is to use the JDBC connection directly, and one is to use the spring connection.
The JDBC connection and access Oracle steps are the same:
Test Phoenix connection///////////////string testsql = "SELECT \" 1\ ", \" 2\ "from Fengji where rowid like ' 1-2017041 3% ' "; try {class.forname (" Org.apache.phoenix.jdbc.PhoenixDriver ");} catch (ClassNotFoundException E1) { System.out.println ("Org.apache.phoenix.jdbc.PhoenixDriver not Found");} List<integer>reslist = new arraylist<integer> (); Connection Con1 = drivermanager.getconnection ("Jdbc:phoenix:ccs01a:2181/hbase", "", "" "); Statement stmt = Con1.createstatement (); ResultSet RSet = Stmt.executequery (Testsql), while (Rset.next ()) {Reslist.add (Rset.getint ("1"));} System.out.println (Reslist.size ()); Stmt.close (); Con1.close ();/////////////////////////////////////
2, Spring and Oracle are basically the same, need to modify the configuration file:
1 <!--Phoenix Configuration -2 <BeanID= "Phoenixjdbctemplate"3 class= "Org.springframework.jdbc.core.JdbcTemplate">4 <Constructor-argref= "Phoenixdatasource"/>5 <Qualifiervalue= "Phoenixjdbctemplate"></Qualifier>6 </Bean>7 <BeanID= "Phoenixdatasource"class= "Org.apache.commons.dbcp.BasicDataSource">8 < Propertyname= "Driverclassname"value= "Org.apache.phoenix.jdbc.PhoenixDriver"/>9 < Propertyname= "url"value= "Jdbc:phoenix:ccs01a:2181/hbase"/>Ten < Propertyname= "username"value=""/> One < Propertyname= "Password"value=""/> A < Propertyname= "InitialSize"value= " the"/> - < Propertyname= "Maxactive"value= "0"/> - <!--because Phoenix does not automatically commit when making data changes, you must add the Defaultautocommit property, otherwise it will cause the data to fail to commit - the < Propertyname= "Defaultautocommit"value= "true"/> - </Bean>
Java Access Phoenix Connection