为什么不从记录中返回完整的数据? [英] why not return complete data from records?
问题描述
为什么不从记录中返回完整的数据?
在记录中,数据是,例如:
ABC,JFKLDJFLDKSJFLDSJFD
但当我查询返回的数据时:
ABC
在,之后的文本,包括,不显示。
这是我的RunDatabse ()在MainActivity.java中,它被称为onCreate(Bundle savedInstaneState):
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):
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;
}
}
这是DatabaseHelper.java中的ReadFromDB(String Selecteditem):
This is ReadFromDB(String Selecteditem) inside DatabaseHelper.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;
}
这是我的数据库中的图片:
http://i.imgur。 com / ra0ZowX.png [ ^ ]
这是返回的图片:
http://i.imgur.com/KGhk857.png [ ^ ]
如何从记录中返回所有完整数据?
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?
推荐答案
您试图添加数据流:
ABC ,JFKLDJFLDKSJFLDSJFD
您必须知道特殊符号,在查询命令中用作分隔符。因此,它只在数据库上执行插入查询时将数据添加到字符,。
希望你得到我想要指定的内容。您只是将结果数据作为您存储在其中的数据量。
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.
这篇关于为什么不从记录中返回完整的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!