使用sqlITE存储,具体可以看SQLITE的语法,比较简单
Ⅱ android 里面怎样将图片上传到数据库
使用Http的get或者post.
Ⅲ android 怎么上传bitmap 到数据库
andorid推荐的是如果数据在20-50k可以存放到数据库,否则数据库存路径。
Ⅳ android中的数据如何导入sqlserver数据库中,求Demo
如果你手机root了的话是可以直接拿到数据库的,没root的话你就在服务端建好数据库和表 然后读取本地数据库上传上去提交到sql service数据库
Ⅳ 如何把批量数据导入到android 的 sqlite 数据库
1、使用db.execSQL(sql)
这里是把要插入的数据拼接成可执行的sql语句,然后调用db.execSQL(sql)方法执行插入。
public void inertOrUpdateDateBatch(List<String> sqls) {
SQLiteDatabase db = getWritableDatabase();
db.beginTransaction();
try {
for (String sql : sqls) {
db.execSQL(sql);
}
// 设置事务标志为成功,当结束事务时就会提交事务
db.setTransactionSuccessful();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 结束事务
db.endTransaction();
db.close();
}
}
2、使用db.insert("table_name", null, contentValues)
这里是把要插入的数据封装到ContentValues类中,然后调用db.insert()方法执行插入。
db.beginTransaction(); // 手动设置开始事务
for (ContentValues v : list) {
db.insert("bus_line_station", null, v);
}
db.setTransactionSuccessful(); // 设置事务处理成功,不设置会自动回滚不提交
db.endTransaction(); // 处理完成
db.close()
3、使用InsertHelper类
这个类在API 17中已经被废弃了
InsertHelper ih = new InsertHelper(db, "bus_line_station");
db.beginTransaction();
final int directColumnIndex = ih.getColumnIndex("direct");
final int lineNameColumnIndex = ih.getColumnIndex("line_name");
final int snoColumnIndex = ih.getColumnIndex("sno");
final int stationNameColumnIndex = ih.getColumnIndex("station_name");
try {
for (Station s : busLines) {
ih.prepareForInsert();
ih.bind(directColumnIndex, s.direct);
ih.bind(lineNameColumnIndex, s.lineName);
ih.bind(snoColumnIndex, s.sno);
ih.bind(stationNameColumnIndex, s.stationName);
ih.execute();
}
db.setTransactionSuccessful();
} finally {
ih.close();
db.endTransaction();
db.close();
}
4、使用SQLiteStatement
查看InsertHelper时,官方文档提示改类已经废弃,请使用SQLiteStatement
String sql = "insert into bus_line_station(direct,line_name,sno,station_name) values(?,?,?,?)";
SQLiteStatement stat = db.compileStatement(sql);
db.beginTransaction();
for (Station line : busLines) {
stat.bindLong(1, line.direct);
stat.bindString(2, line.lineName);
stat.bindLong(3, line.sno);
stat.bindString(4, line.stationName);
stat.executeInsert();
}
db.setTransactionSuccessful();
db.endTransaction();
db.close();
Ⅵ android信息发布系统 需要通过content:uri上传图片到服务器数据库,不知道怎么开始,求解
可以用http上传啊,当文件上传就行了
// 1.多部分的实体
MultipartEntity reqEntity = new MultipartEntity();
// 2.增加
String[] mimeTypeList = pairMap.keySet().toArray(new String[1]);
for(String mimeType : mimeTypeList){
List<NameValuePair> pairs = pairMap.get(mimeType);
if (pairs != null) {
if (mimeType.equals("String")) {
for (int i = 0; i < pairs.size(); i++) {
reqEntity.addPart(pairs.get(i).getName(),new StringBody(pairs.get(i).getValue(), Charset.forName("utf-8")));
}
}else {
for (int i = 0; i < pairs.size(); i++) {
File file = new File(pairs.get(i).getValue());
ContentBody cbFile = new FileBody(file);//, mimeType);
reqEntity.addPart(pairs.get(i).getName(), cbFile);
}
}
}
}
Ⅶ android怎么把数据存入数据库
把数据放入数据库
通过把ContentValues对象传入instert()方法把数据插入数据库:
// Gets the data repository in write mode
SQLiteDatabase db = mDbHelper.getWritableDatabase();
// Create a new map of values, where column names are the keys
ContentValues values = new ContentValues();
values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_ENTRY_ID, id);
values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_TITLE, title);
values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_CONTENT, content);
// Insert the new row, returning the primary key value of the new row
long newRowId;
newRowId = db.insert(
FeedReaderContract.FeedEntry.TABLE_NAME,
FeedReaderContract.FeedEntry.COLUMN_NAME_NULLABLE,
values);
insert()方法的第一个参数是表名。第二个参数提供了框架中的一个列名,在ContentValues的值是空的时候,框架会向表中插入NULL值(如果这个参数是“null”,那么当没有值时,框架不会向表中插入一行。
从数据库中读取数据
要从数据库中读取数据,就要使用query()方法,你需要给这个方法传入选择条件和你想要获取数据的列。查询结果会在Cursor对象中被返回。
SQLiteDatabase db = mDbHelper.getReadableDatabase();
// Define a projection that specifies which columns from the database
// you will actually use after this query.
String[] projection = {
FeedReaderContract.FeedEntry._ID,
FeedReaderContract.FeedEntry.COLUMN_NAME_TITLE,
FeedReaderContract.FeedEntry.COLUMN_NAME_UPDATED,
...
};
// How you want the results sorted in the resulting Cursor
String sortOrder =
FeedReaderContract.FeedEntry.COLUMN_NAME_UPDATED + " DESC";
Cursor c = db.query(
FeedReaderContract.FeedEntry.TABLE_NAME, // The table to query
projection, // The columns to return
selection, // The columns for the WHERE clause
selectionArgs, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);
使用Cursor对象的移动方法来查看游标中的一行数据,在开始读取数据之前必须先调用这个方法。通常,应该从调用moveToFirst()方法开始,它会把读取数据的位置放到结果集中第一实体。对于每一行,你可以通过调用Cursor对象的相应的get方法来读取列的值,如果getString()或getLong()方法。对于每个get方法,你必须把你希望的列的索引位置传递给它,你可以通过调用getColumnIndex()或getColumnIndexOrThrow()方法来获取列的索引。例如:
cursor.moveToFirst();
long itemId = cursor.getLong(
cursor.getColumnIndexOrThrow(FeedReaderContract.FeedEntry._ID)
);
从数据库中删除数据
要从一个表中删除行数据,你需要提供标识行的选择条件。数据API为创建选择条件提供了一种机制,它会防止SQL注入。这中机制把选择条件分成了选择条件和选择参数。条件子句定义了要查看的列,并且还允许你使用组合列来进行筛选。参数是用于跟条件绑定的、用户筛选数据的值。因为这样不会导致像SQL语句一样的处理,所以它避免了SQL注入。
// Define 'where' part of query.
String selection = FeedReaderContract.FeedEntry.COLUMN_NAME_ENTRY_ID + " LIKE ?";
// Specify arguments in placeholder order.
String[] selelectionArgs = { String.valueOf(rowId) };
// Issue SQL statement.
db.delete(table_name, selection, selectionArgs);
更新数据库
当你需要编辑数据库值的时候,请使用update()方法。
这个方法在更新数据时会把insert()方法中内容值的语法跟delete()方法中的where语法结合在一起。
SQLiteDatabase db = mDbHelper.getReadableDatabase();
// New value for one column
ContentValues values = new ContentValues();
values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_TITLE, title);
// Which row to update, based on the ID
String selection = FeedReaderContract.FeedEntry.COLUMN_NAME_ENTRY_ID + " LIKE ?";
String[] selelectionArgs = { String.valueOf(rowId) };
int count = db.update(
FeedReaderDbHelper.FeedEntry.TABLE_NAME,
values,
selection,
selectionArgs);
Ⅷ android百度消息推送过来的数据如何存入数据库
可以通过getText()方法,首先需要的到输入的值,然后调用数据库的插入方法 db.insert();插入到数据库中就行;这样数据就存入数据库了。消息推送的行业应用
1、广告推送
信息推送最热门的应用方向是广告推送,也就是互联网效果营销的应用方向。
2、社区信息
大量的web2.0社区,也激发了社区信息的推送应用。基于用户关系、用户行为,给用户推送用户感兴趣的信息,包括帖子、任务、游戏,等等。
对于消息推送软件,推荐使用深圳极光家的消息推送软件。极光是国内领先的移动开发者服务提供商,极光会根据前者的年龄、性别和兴趣等标签帮助企业设计广告页面,并在网络、腾讯、阿里妈妈、今日头条等多家主流媒体上通过广告的方式向用户投放具有针对性和吸引力的促销优惠信息。
Ⅸ android 怎么往数据库里面添加数据
一、引入
数据库创建的问题解决了,接下来就该使用数据库实现应用程序功能的时候了。基
本的操作包括创建、读取、更新、删除,即我们通常说的 CRUD(Create, Read, Update, Delete)。
在实现这些操作的时候,我们会使用到两个比较重要的类 SQLiteDatabase 类和 Cursor 类。
二、创建表
1,execSQL(String sql):执行一条 sql 语句,且执行操作不能为 SELECT
因为它的返回值为 void,所以推荐使用 insert、update 方法等
2.,execSQL (String sql,Object[] bindArgs)
sql:执行一条 sql 语句
bindArgs:为 sql 语句中的?赋值
三、添加数据
1、execSQL(String sql)
2、使用对象的 insert 方法
ContentValues values = new ContentValues();
values.put(USERNAME, user.getUsername());
values.put(PASSWORD, user.getPassword());
db.insert(TABLE_NAME, null, values);
参数:
table:数据库中的表名
nullColumnHack:指定默认插入字段,为 null 时能插入数据
values:表示插入字段所对应的值,使用 put 方法。
四、删除数据
1、execSQL(String sql)
2、使用对象的 delete 方法
String whereClaues="_id=?";
String [] whereArgs={String.valueOf(id)};
//db.delete(TABLE_NAME, "_id="+id, null);
db.delete(TABLE_NAME, whereClaues, whereArgs);
参数
table:数据库的表名
whereClause:where 子句,比如:_id=?
whereArgs:where 子句中?的值
五、修改数据
1、execSQL(String sql)
2、使用对象的 delete 方法
ContentValues values = new ContentValues();
values.put(USERNAME, user.getUsername());
values.put(PASSWORD, user.getPassword());
String whereClaues="_id=?";
String [] whereArgs={String.valueOf(user.getId())};
db.update(TABLE_NAME, values, whereClaues, whereArgs);
参数
table:数据库的表名
values:代表要修改的值,修改方法还是 put(key,values)
whereClause:条件子句,比如 id=?,name=?
whereArgs:为 whereClause 中的?赋值,比如:new String[]{"1","张三"}
图:
参考代码:
程序内使用SQLite数据库是通过SQLiteOpenHelper进行操作
1.自己写个类继承SQLiteOpenHelper,重写以下3个方法
publicvoidonCreate(SQLiteDatabasedb)
{//创建数据库时的操作,如建表}
publicvoidonUpgrade(SQLiteDatabasedb,intoldVersion,intnewVersion)
{
//版本更新的操作
}
2.通过SQLiteOpenHelper的getWritableDatabase()获得一个SQLiteDatabase数据库,以后的操作都是对SQLiteDatabase进行操作。
3.对得到的SQLiteDatabase对象进行增,改,删,查等操作。
代码
packagecx.myNote;
importandroid.content.ContentValues;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.database.Cursor;
importandroid.database.sqlite.SQLiteDatabase;
importandroid.database.sqlite.SQLiteOpenHelper;
//DBOptionsforlogin
publicclassDBOptions{
privatestaticfinalStringDB_NAME="notes.db";
privatestaticfinalStringDB_CREATE="createtablelogininf(nametext,pwdtext)";
{
publicDBHelper(Contextcontext){
super(context,DB_NAME,null,1);
}
@Override
publicvoidonCreate(SQLiteDatabasedb){
//TODOAuto-generatedmethodstub
//建表
db.execSQL(DB_CREATE);
}
@Override
publicvoidonUpgrade(SQLiteDatabasedb,intoldVersion,intnewVersion){
//TODOAuto-generatedmethodstub
db.execSQL("droptableifexistslogininf");
onCreate(db);
}
}
privateContextcontext;
privateSQLiteDatabasedb;
privateDBHelperdbHelper;
publicDBOptions(Contextcontext)
{
this.context=context;
dbHelper=newDBHelper(context);
db=dbHelper.getReadableDatabase();
}
//自己写的方法,对数据库进行操作
publicStringgetName()
{
Cursorcursor=db.rawQuery("selectnamefromlogininf",null);
cursor.moveToFirst();
returncursor.getString(0);
}
publicintchangePWD(StringoldP,Stringpwd)
{
ContentValuesvalues=newContentValues();
values.put("pwd",pwd);
returndb.update("logininf",values,"pwd="+oldP,null);
}
}
insert方法插入的一行记录使用ContentValus存放,ContentValues类似于Map,它提供了put(String key, Xxx value)(其中key为数据列的列名)方法用于存入数据、getAsXxxx(String key)方法用于取出数据