保存数据(3)sqlLite保存数据

保存数据(3)sqlLite保存数据,第1张

概述1 内存数据库存储 String createTableSQL = "CREATE TABLE [t_test] (" + "[id] INTEGER," + "[name] VARCHAR(20),[memo] TEXT," + "CONSTRAINT [sqlite_autoindex_t_test_1] PRIMARY KEY ([id]))"; SQLiteDataba

1 内存数据库存储

@H_403_3@

String createtablesql = "CREATE table [t_test] (" + "[ID] INTEGER,"				+ "[name] VARCHAR(20),[memo] TEXT,"				+ "CONSTRAINT [sqlite_autoindex_t_test_1] PRIMARY KEY ([ID]))";		sqliteDatabase sqliteDatabase = sqliteDatabase.create(null);		sqliteDatabase.execsql(createtablesql);		String insertsql = "insert into t_test(ID,name) values(?,?)";		sqliteDatabase.execsql(insertsql,new Object[] 		{ 1,"老毕" });  		String selectsql = "select name from t_test";		Cursor cursor = sqliteDatabase.rawquery(selectsql,null);		cursor.movetoFirst();		Toast.makeText(this,cursor.getString(0),Toast.LENGTH_LONG).show();		sqliteDatabase.close();
@H_403_3@ 2 物理文件数据库存储
String filename = androID.os.Environment.getExternalStorageDirectory()				+ "/sdcard_test.db";		String createtablesql = "CREATE table [t_test] (" + "[ID] INTEGER,"				+ "CONSTRAINT [sqlite_autoindex_t_test_1] PRIMARY KEY ([ID]))";		file file = new file(filename);		if (file.exists())		{			file.delete();		}		sqliteDatabase database = sqliteDatabase.openorCreateDatabase(filename,null);		database.execsql(createtablesql);		ContentValues contentValues = new ContentValues();		contentValues.put("ID",1);		contentValues.put("name","Mike");		contentValues.put("memo","Student");		database.insert("t_test",null,contentValues);		String insertsql = "insert into t_test(ID,name,memo) values(?,?,?)";		database.execsql(insertsql,new Object[]{2,"John","��ʦ"});		String selectsql = "select name,memo from t_test where name=?";		Cursor cursor = database.rawquery(selectsql,new String[]		{ "John" });		cursor.movetoFirst();		Toast.makeText(this,cursor.getString(0) + "  " + cursor.getString(1),Toast.LENGTH_LONG).show();				database.close();
总结

以上是内存溢出为你收集整理的保存数据(3)sqlLite保存数据全部内容,希望文章能够帮你解决保存数据(3)sqlLite保存数据所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1176785.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存