我正在制作这个Android应用程序。应用程序上的页面必须显示数据库中2个不同列的数据,它必须从workshop表中收集数据,以及workshopid相等的scheduleles表。我知道我必须在workshopid上使用内部连接,但这似乎对我没用。
这是我现在的代码:
private void GetInfo(String eventName, String workshopName) {
String GetInfo = null;
String dbResult = "empty";
dbConnect database = new dbConnect(this);
try{
String query = "SELECT workshopid, scedules.workshopid, scedules.starttime, scedules.endtime, workshopname, workshopdesc FROM workshops INNER JOIN scedules ON workshops.workshopid = scedules.workshopid WHERE workshopname = '" + workshopName + "';";
GetInfo = "?query=" + URLEncoder.encode(query, "UTF-8");
String link = "https://jackstest.000webhostapp.com/androiddbconnect.php" + GetInfo;
dbResult = database.execute(link).get();
}
catch(Exception e){
Header.setText("Workshop");
}
try{
JSONArray ja = new JSONArray(dbResult);
JSONObject jo = null;
data = new String[ja.length()];
data2 = new String[ja.length()];
for (int i = 0;i < 1 ; i++){
jo = ja.getJSONObject(i);
data[i] = jo.getString("workshopname");
data2[i] = jo.getString("workshopdesc");
}
Header.setText(data[0]);
Content.setText(data2[0]);
Location.setText("Locatie : " + eventName);
}
catch(Exception e){
e.printStackTrace();
}
研讨会内容表:
workshopid: "1",
workshopname: "Workshop1",
imagelink: "",
workshopdesc: " Lorem ipsum dolor sit amet"
日程表的内容:
eventid: "1",
workshopid: "1",
starttime: "13:23:00",
endtime: "13:25:00",
date: "2018-04-03"
在这两个表格中,我需要workshop workshop,workshopdesc,imagelink。从时间表中我需要开始时间,结束时间和日期。
答案 0 :(得分:0)
尝试使用此SQL语句,看看它是否提供了您期望的结果:
String query = "SELECT w.workshopid, s.starttime, s.endtime, w.workshopname, w.workshopdesc
FROM workshops AS w
INNER JOIN scedules AS s ON
w.workshopid = s.workshopid
WHERE w.workshopname = '" + workshopName + "';";
如果这不起作用,我将需要知道您正在访问的数据库类型(MySQL,MS SQL,...)。
另外:我注意到这行代码:
database.execute(link).get();
database
是AsyncTask
吗?如果是这样,那么使用方法get()
将阻止你线程直到响应回来 - 有效地使AsyncTask
无用。