簡體   English   中英

在Android中從數據庫中獲取值時出現問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM