在登录页面后,我想在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;
}
之前的初始化过程中,你有没有把值放入session 中去啊?设置一下断点,跟踪一下,如果有值的话就看看这个 *** 作有没有什么问题,比如你存到session里的是不是(userManager,"userid")这组值,如果不是的话就看看你得到的session对不对,有没有值。
int maxAttempts = 3;
SqlConnection conn = new SqlConnection(connectionString);
connOpen();
string commandText = "select TOP 1 ID from A";
int getID= 0;
for (int j = 0; j < maxAttempts; j++)
{
try
{
SqlCommand cmd = new SqlCommand();
cmdCommandText = commandText;
cmdCommandType = CommandTypeText;
cmdConnection = conn;
cmdCommandTimeout = 60;
getID= ConvertToInt32(cmdExecuteScalar());
cmdDispose();
break;
}
catch (SqlException ex)
{
ConsoleWriteLine(commandText);
ConsoleWriteLine(exMessage + " Retrying");
getID= -1;
}
}
connClose();
LINQ:
var getIDs = from a in myDBContextA
select aID;
int getID = getIDsMAX(); //FirstOrDefault()
一下是显示到Table的关键代码,希望可以帮助你! public void ProcessRequest(>
以上就是关于如何从sqlite数据库中获取数据并显示在listview中全部的内容,包括:如何从sqlite数据库中获取数据并显示在listview中、UserTable userManager=(UserTable) ActionContext.getContext().getSession().get("userId");得不到值啊、C# 如何获得数据库中指定列的值.等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)