-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBHelper.java
More file actions
192 lines (155 loc) · 6.38 KB
/
DBHelper.java
File metadata and controls
192 lines (155 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package com.example.smash;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class DBHelper extends SQLiteOpenHelper {
public static final String DBNAME = "DB";
private SQLiteDatabase userInfo;
static List<String> infoList;
public DBHelper(@Nullable Context context) {
super(context, "DB", null, 1);
}
@Override
public void onCreate(SQLiteDatabase DB) {
DB.execSQL("create Table LoginDB(school TEXT, user TEXT primary key, password TEXT)");
DB.execSQL("create Table InfoDB(name TEXT, department TEXT, grade TEXT, interest TEXT, time TEXT, place TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase Login, int oldVersion, int newVersion) {
Login.execSQL("drop Table if exists users");
}
public Boolean insertData(String school, String user, String password) {
SQLiteDatabase MyDB = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("school", school);
contentValues.put("user", user);
contentValues.put("password", password);
long result = MyDB.insert("LoginDB", null, contentValues);
if (result == -1) return false;
else
return true;
}
public Boolean checkusernamepassword(String school, String user, String password) {
SQLiteDatabase MyDB = this.getWritableDatabase();
Cursor cursor = MyDB.rawQuery("Select * from LoginDB where school = ? and user = ? and password = ?", new String[]{school, user, password});
if (cursor.getCount() > 0)
return true;
else
return false;
}
public Boolean insertInfo(String name, String department, String grade, String interest, String time, String place){
SQLiteDatabase MyDB = this. getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("name", name);
contentValues.put("department", department);
contentValues.put("grade", grade);
contentValues.put("interest", interest);
contentValues.put("time", time);
contentValues.put("place", place);
long result = MyDB.insert("InfoDB", null, contentValues);
if(result == -1) return false;
else
return true;
}
public List<String> selectInfo(String name, String department, String grade, String interest, String time, String place){
SQLiteDatabase MyDB = this.getWritableDatabase();
String SELECT_QUERY = "SELECT*FROM InfoDB where name = ? and department = ? and grade = ? and interest = ? and time = ? and place = ?";
Cursor cur = MyDB.rawQuery(SELECT_QUERY,new String[]{name, department, grade, interest, time, place});
int i=0;
infoList = new ArrayList<>();
while(cur.moveToNext()){
infoList.add(cur.getString(i));
i++;
}
return infoList;
}
/*
public static final String DBNAME = "Login.db";
public DBHelper(@Nullable Context context) {
super(context, "Login.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase MyDB) {
MyDB.execSQL("create Table users(school TEXT, user TEXT primary key, password TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase MyDB, int oldVersion, int newVersion) {
MyDB.execSQL("drop Table if exists users");
}
public Boolean insertData(String school, String user, String password){
SQLiteDatabase MyDB = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("school", school);
contentValues.put("user", user);
contentValues.put("password", password);
long result = MyDB.insert("users", null, contentValues);
if (result==-1) return false;
else
return true;
}
public Boolean checkusername(String username) {
SQLiteDatabase MyDB = this.getWritableDatabase();
Cursor cursor = MyDB.rawQuery("Select * from users where username = ?", new String[] {username});
if (cursor.getCount()>0)
return true;
else
return false;
}
public Boolean checkusernamepassword(String school, String user, String password) {
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("Select * from users where school = ? and user = ? and password = ?", new String[] {school,user,password});
if (cursor.getCount()>0)
return true;
else
return false;
}*/
/*
static final String DATABASE_NAME = "test.db";
public DBHelper(Context context, int version){
super(context, DATABASE_NAME, null, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE Person(name TEXT, Age INT, ADDR TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS Person");
onCreate(db);
}
public void Insert(String School, String Name, String PassWord){
SQLiteDatabase db = getWritableDatabase();
db.execSQL("INSERT INTO Person VALUES('"+ School + "', " + Name + ", '"+ PassWord + "')");
db.close();
}
public void Update(String School, String Name, String PassWord){
SQLiteDatabase db = getWritableDatabase();
db.execSQL("UPDATE Person SET School = " + School + ", PassWord = '" + PassWord + "'" + " WHERE NAME = '" + Name + "'");
}
public void Delete(String Name){
SQLiteDatabase db = getWritableDatabase();
db.execSQL("DELETE Person WHERE NAME = '" + Name + "'");
db.close();
}
public String getResult(){
SQLiteDatabase db = getReadableDatabase();
String result = "";
Cursor cursor = db.rawQuery("SELECT * FROM Person", null);
while(cursor.moveToNext()){
result += "학교 : " + cursor.getString(0)
+ ", 이름 : "
+ cursor.getString(1)
+ ", 비밀번호 : "
+ cursor.getString(2)
+"\n";
}
return result;
}
}
*/
}