Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
why not return complete data from records?

In a record, the data is,for example,:

ABC, JFKLDJFLDKSJFLDSJFD

But when I queried the returned data is:

ABC

texts after "," and including "," are not displayed.

This is my RunDatabse() inside MainActivity.java, it's called onCreate(Bundle savedInstaneState):


Java
public void RunDatabse() {
			DatabaseHelper myDbHelper = new DatabaseHelper(this);
			//Toast.makeText(this,Selecteditem,Toast.LENGTH_LONG).show();
			 
			try {
			 
			myDbHelper.createDataBase();
			DataToDB = myDbHelper.ReadFromDB("Exodus");//sending the selected spinner item to database for query
			TableLayout tablelayout1= (TableLayout)findViewById(R.id.tableLayout1);
	        tablelayout1.removeAllViews();
	        
	        for(int i=0;i < DataToDB.length;i++)//repeat adding raws to the table layout till the string array length ends
   	     {
   	        
	        	//Adding raws to the Table dynamically
   	     		TableRow tR = new TableRow(this);
   	         	result_array = DataToDB[i].split(","); //splitting the comma separated string array
   	         	  //result_array is the string array for storing result.it is defined in top       	
   	             tR.setPadding(5,5,5,5); //setting spacing between table raws             
   	             TextView tV_txt1 = new TextView(this);//adding textViews to each Table cell
   	             TextView tV_txt2 = new TextView(this);
   	        
   	                      
   	                       
   	             tV_txt1.setText(result_array[0]);//setting the first array item to text view
   	             
   	             
   	             tV_txt2.setText(result_array[1]);
   	             
   	             
   	      
   	            
   	             
   	                        
   	             tR.addView(tV_txt1);
   	             tR.addView(tV_txt2);
   	           
   	             

   	             tablelayout1.addView(tR);//Adding all Table raws to the Table
   	     	
   	     } 
			
	}
	 catch (IOException ioe) {
			 
			throw new Error("Unable to create database");
			 
			}
			 
			try {
			 
			try {
				myDbHelper.openDataBase();
			} catch (java.sql.SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 
			}catch(SQLException sqle){
			 
			throw sqle;
			 
			} 
		}




This is ReadFromDB(String Selecteditem) inside DatabaseHelper.java:


Java
  public String[] ReadFromDB(String Selecteditem) {
     // Retrieve a string array of all our Data
  //Toast.makeText(this.myContext,"Read From DB",Toast.LENGTH_LONG).show();

  ArrayList temp_array = new ArrayList();
  String[] notes_array = new String[0];
  //The SQL Query


  String sqlQuery = "SELECT * FROM "+Selecteditem+" WHERE chapter='8'" ;

  //Here we are querying the databse with the selected item from the spinner. Only the data with the slected item will be retrived from the databse

  //Define database and cursor

  //Toast.makeText(this.myContext,sqlQuery,Toast.LENGTH_LONG).show();

  SQLiteDatabase db = this.getWritableDatabase();
  Cursor c = db.rawQuery(sqlQuery, null);

  //Loop through the results and add it to the temp_array


            if (c.moveToFirst()){
                do{
                      temp_array.add(  c.getString(c.getColumnIndex("verse")) +
                                 "," + c.getString(c.getColumnIndex("content"))
                                 );

            //Toast.makeText(this.myContext,c.getString(c.getColumnIndex("TIME")),Toast.LENGTH_LONG).show();




      }while(c.moveToNext());
   }
  //Close the cursor
  c.close();
  //Transfer from the ArrayList to string array
  notes_array = (String[]) temp_array.toArray(notes_array);
  //Return the string array
  return notes_array;
}




Here is the picture inside my database:

http://i.imgur.com/ra0ZowX.png[^]


Here is the picture returned:


http://i.imgur.com/KGhk857.png[^]




how to return all complete data from records?
Posted

1 solution

You have tried to add the data stream:
ABC, JFKLDJFLDKSJFLDSJFD

As you must know that special symbol "," is used as a separator in Query Commands. So, it has only added the data upto the character "," while executing the insert query on the database.

Hope you got what exactly I want to specify. You are just getting the result data as the amount of data stored in it by you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900