OpenHelper文件中:
public class OpenHelper extends SQLiteOpenHelper {
//新建一个学生数据库
public OpenHelper(Context context) {
super(context, "student.db", null, 1);
}
//创建一个学生表
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table student(id integer primary key autoincrement,name varchar(50),pwd varchar(50))");
}
UserDao文件中:
//通过用户名和密码查寻是否存在该学生
public int findStuBynamePWD(String name,String pwd){
int count = 0;
SQLiteDatabase db = null;
Cursor cursor = null;
//执行创建数据库或是表的语句
db = openHelper.getReadableDatabase();
//执行通过用户名和密码的参数查询出用户,并保存在cursor中
cursor = db
.rawQuery(
"select count(*) as count from student where name=? and pwd=?",
new String[] { name, pwd });
//得到的用户信息通过moveToNext()方法,while语句循环输出
while (cursor.moveToNext()) {
//把
count = cursor.getInt(cursor.getColumnIndex("count"));
}
}
LoginActivity文件关键代码中:
UserDao userDao=new UserDao(LoginActivity.this);
if(userDao.findStuBynamePWD(nameNum, pwdNum)>0){
//如果存在就跳到MainActivity
startActivity(intent);
} //用户名和密码输入有误!
else{
Toast.makeText(LoginActivity.this, "用户名或密码有误,请重新输入!",
Toast.LENGTH_SHORT).show();
}
问题:添加新表的时,在OpenHelper文件中,在onCreate方法中添加语句下面:db.execSQL("create table admin(a_id integer primary key autoincrement,a_name varchar(20),a_pwd varchar(20))"),我在SQLite语句是可以运行。运行工程时,没有新表?怎么改,跪求大神!!!