Java数据库处理的方法库DBUtil(3)
发布时间:2021-06-07
发布时间:2021-06-07
Keyspace keyspace = client.getKeyspace(”skyups”);
ColumnPath columnPath = new ColumnPath();
columnPath.setColumn_family(”UserInfo”);
//delete
keyspace.remove(USkyid, columnPath);
/*
// read
Column col = keyspace.getColumn(value, columnPath);
System.out.println(”Read from cassandra: ” +
string(col.getValue()));
// insert
keyspace.insert(”key”, columnPath, bytes(”value”)); */
} finally{
pool.releaseClient(client);
}
}
利用方法库执行一次完整的junit测试举例:
step1.设置一条用户信息,包括所有字段参数。step2:再发送一条设置信息,其中用户的出生日期为空。step3:删除这条用户信息,恢复环境。
@Before
public void setUp() throws Exception {
Socket socket=new Socket(ServerIP,Port);
DataOutputStream dos=new DataOutputStream(socket.getOutputStream()); DataInputStream dis=new DataInputStream(socket.getInputStream()); byte[] resp=new byte[1024];
System.out.println(”StartUp:预置测试环境,初始化设置1条用户信息“); byte[] setuserinfomsg1=PackMsg.SetUserInfoMsg(USkyid, UUserName,
UNickname, URealName, USex, UBirthday, UAnimals, UStar, UBlood, UMarried, UPortraitId, UDefinePortrait, UCountry, UProvince, UCity, UHometown, ULongitude, ULatitude, USignature, UDesc, UEmail, UEmailChecked, UMobile, UMobileChecked, UTelephone, UVocation, USchoolGraduated, UPrivacy, UIdCardNo,HasPic);
dos.write(setuserinfomsg1);dis.read(resp);
Thread.sleep(1000);
dos.flush();dis.close();socket.close();
}