作者:军长长军765 | 来源:互联网 | 2023-01-02 19:09
MyquestionhastodowithstoringarraysandArrayListsinSQLite.IhaveanObjectCourseasfollo
My question has to do with storing arrays and ArrayLists in SQLite. I have an Object Course as follows:
我的问题与在SQLite中存储数组和数组列表有关。我有一个目标课程如下:
public class Course {
private String name;
private ArrayList tees;
which contains the ArrayList of Tee where Tee looks like this:
它包含三通的数组列表,其中三通看起来是这样的:
public class Tee {
private String Name;
private int Slope;
private double Rating;
private int[] Par={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
private int[] HCP={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
Each Course has a number of Tees associated with it and each Tee contains 2 integer arrays. I want to store a list of Courses in a SQLite database. Each row of the database will represent a Course and contain the Course object data. I have researched this and I find either too little or too much information to be helpful.
每门课程都有许多与之相关的三通,每个三通包含两个整数数组。我想在一个SQLite数据库中存储一个课程列表。数据库的每一行将表示一个课程,并包含课程对象数据。我研究过这个问题,发现信息太少或太多都没有帮助。
I think I need to use a JSON object or a BLOB to convert the ArrayLists to something that can be stored in SQLite, but I can't seem to find the way to convert an int array into such a thing (BLOB or JSON Object or JSON Array?) and then the subsequent list of Tees into another thing (BLOB, etc.)
我想我需要使用JSON对象或一个BLOB ArrayLists转换为可以存储在SQLite的东西,但我似乎无法找到一个int数组转换成这种事(BLOB或JSON对象或JSON数组?),然后后续的t恤列表到另一件事(BLOB等。)
2 个解决方案
0
You have to create the framework for retrieving data.
您必须创建检索数据的框架。
Each course you should treat like one object.
每一门课你都应该像对待一个对象一样对待。
public class Tee {
private String Name;
private int Slope;
private double Rating;
private int[] Par={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
private int[] HCP={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
public Tee(String name,int slope,double Rating,int[] par,int[] hcp)
{
this.name=name;
this.slope=slope;
this.Rating=rating;
this.PAR=par;
this.HCP=hcp;
}
public String GetName()
{
return this.name;
}
....
public int[] GetHCP()
{
return this.HCP;
}
}
And Use for loop for inserting data into the database
用于将数据插入数据库的循环
for(int i=0;i
For PAR and HCP data storing, please do the table indexing for good way manage your data flow
对于PAR和HCP数据存储,请执行表索引,以便更好地管理数据流