[英]Problem in fetching the value from the database in android
在我的应用程序中,我正在使用sql服务器数据库来存储和检索数据库中的值。 现在,我正在获取每一行,并在每列数据之间添加“〜”。 在调用函数时,我用相同的(〜)拆分了它。 现在我的问题是,如果数据库中某些字段为空,那么我没有返回空间,那么我该如何管理要在写入位置显示的空白数据。 我对此很陌生。 如果知道一个可以理解的情况,请随时提出。 感谢你。
//Function Definition
public String[] selectPhoneDirectory(String siteId){
String[] detailofemployee = new String[25];
openConnection();
String query = "Select * from Telephone_master with(nolock) where Site_ID = '"+siteId+"' order by User_Name";
int i =0;
try{
rs = st.executeQuery(query);
while(rs.next()){
detailofemployee[i] = rs.getString(3)+"~"+rs.getString(4)+"~"+rs.getString(5)+"~"+rs.getString(6)+"~"+rs.getString(7);
System.out.println("The Detail Is :"+detailofemployee[i]);
i++;
}
}
catch (Exception e) {
System.out.println("Error!!!"+e);
}
closeConnection();
return detailofemployee;
}
//Calling Function
for(int i = 0; i < siteName.length; i++){
if(siteName[i].equalsIgnoreCase(strselectedName)){
detailEmployee = gd.selectPhoneDirectory(siteId[i]);
}
for(int j = 0 ;j < detailEmployee.length ; j++){
StringTokenizer st =new StringTokenizer(detailEmployee[j]);
empName[j] = new String();
empName[j] = st.nextToken("~").toString();
System.out.println("The Name Is :"+empName[j]);
empHome[j] = new String();
empHome[j] = st.nextToken("~").toString();
System.out.println("The Home No Is :"+empHome[j]);
empMob[j] = new String();
empMob[j] = st.nextToken("~").toString();
System.out.println("The Mobile No Is :"+empMob[j]);
}
String myStr =yourTableRaw ;
使用replaceAll
方法
用一个〜字符替换连续的〜
myStr = myStr.replaceAll("~+","~");
然后进行分割通话
String result []= myStr.split("~");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.