
在登录页面后,我想在listview中把Apple显示成A,Boy显示成B等等,直到F。但是在程序中当我完全登录后,只有登录表成功创建,主菜单还是没有创建。
我想在test database中创建主菜单,然后我想从主菜单表(mainmenu table)中获取数据再显示在listview中。
我使用了下面的代码:
if(usernamelength()>0&&passwordlength()>0)
{
SQLiteAdapter db=new SQLiteAdapter(Mainthis);
dbopenToWrite();
if(dbLogin(username,password))
{
Systemoutprintln("goutham");
Intent intent=new Intent(getApplicationContext(),ExampleActivityclass);
startActivity(intent);
}
SQLiteAdapterjava
}
public Cursor queueAll() {
String[] columns = new String[] { KEY_ID, KEY_CONTENT };
Cursor cursor = sqLiteDatabasequery(MYDATABASE_TABLE, columns, null,
null, null, null, null);
return cursor;
}
private static class SQLiteHelper extends SQLiteOpenHelper {
public SQLiteHelper(Context context, String name,
CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
dbexecSQL(SCRIPT_CREATE_DATABASE);
dbexecSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
public long AddUser(String username, String password) {
ContentValues initialValues = new ContentValues();
initialValuesput(KEY_USERNAME, username);
initialValuesput(KEY_PASSWORD, password);
return sqLiteDatabaseinsert(DATABASE_TABLE, null, initialValues);
}
public boolean Login(String username, String password) {
// TODO Auto-generated method stub
Cursor mCursor = sqLiteDatabaserawQuery("SELECT FROM "
+ DATABASE_TABLE + " WHERE username= AND password=",
new String[] { username, password });
if (mCursor != null) {
if (mCursorgetCount() > 0) {
return true;
}
}
return false;
}
}
ExampleActivityjava
public class ExampleActivity extends Activity {
private SQLiteAdapter mySQLiteAdapter;
/ Called when the activity is first created /
@Override
public void onCreate(Bundle savedInstanceState) {
superonCreate(savedInstanceState);
setContentView(Rlayoutmain);
ListView listContent = (ListView) findViewById(Ridcontentlist);
/
Create/Open a SQLite database and fill with dummy content and close
it
/
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapteropenToWrite();
// mySQLiteAdapterdeleteAll();
mySQLiteAdapterinsert("A for Apply");
mySQLiteAdapterinsert("B for Boy");
mySQLiteAdapterinsert("C for Cat");
mySQLiteAdapterinsert("D for Dog");
mySQLiteAdapterinsert("E for Egg");
mySQLiteAdapterinsert("F for Fish");
mySQLiteAdapterclose();
/
Open the same SQLite database and read all it's content
/
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapteropenToRead();
Cursor cursor = mySQLiteAdapterqueueAll();
startManagingCursor(cursor);
String[] from = new String[] { SQLiteAdapterKEY_CONTENT };
int[] to = new int[] { Ridtext };
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this,
Rlayoutrow, cursor, from, to);
listContentsetAdapter(cursorAdapter);
mySQLiteAdapterclose();
}
}
运行程序后,登录表在数据库中创建了,但是主菜单表没有创建。运行程序后,显示一个错误:
sqlite returned code=1 no such a table in MY_TABLE
通过互联网整理获得以下解决方法:
=================1楼=====================
Database class:
public String getData1() throws SQLException{
// TODO Auto-generated method stub
String[] columns1 = new String[] { KEY_DATE };
Cursor c1 = ourDatabasequery(DATABASE_MARKSTABLE, columns1, null, null, null,
null, KEY_ENDINGTIME+" DESC", " 30");
String result1 = "";
int isName = c1getColumnIndex(KEY_DATE);
for (c1moveToFirst(); !c1isAfterLast(); c1moveToNext()) {
result1 = result1 + c1getString(isName)
+ " " + "\n";
}
c1close();
return result1;
}
在String
value
=
rsgetString("name");
之前要先rsnext();一下
你用这个来判断密码错误?
if(!rsisBeforeFirst()){
JOptionPaneshowMessageDialog(frame,
"Wrong
password!");
}
isBeforeFirst()
的意思是:获取光标是否位于此
ResultSet
对象的第一行之前。
用时间检出数据。mysql获取增量数据信息简书的方法是以时间字段为条件,检出新增数据列出简书,MySQL是一个关系型数据库管理系统,是最流行的关系型数据库管理系统之一,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。
以上就是关于如何从sqlite数据库中获取数据并显示在listview中全部的内容,包括:如何从sqlite数据库中获取数据并显示在listview中、java读取MySQL数据库、mysql怎么获取增量数据信息简书等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)