- 浏览: 75952 次
- 性别:
- 来自: 西安
文章分类
- 全部博客 (101)
- Android (45)
- java中多线程的实现 (1)
- Runnable (2)
- Thread (1)
- TCP网络编程 (1)
- PHP (1)
- java (4)
- JDBC (1)
- oauth登录 (1)
- 中文乱码 (1)
- Ajax (1)
- web (2)
- Mysql (2)
- HTML5 (0)
- HTML5 (1)
- entity not found (1)
- JQuery (2)
- 使用jsp和Servlet实现一个验证码 (1)
- 验证码 (1)
- 异常 (1)
- webService (2)
- not insert异常 (1)
- JAVAmail (1)
- 选中分享 (1)
- 控件 (1)
- 方法 (1)
- listView (1)
- android控件 (1)
- jqueryMobile (1)
- servlet开发中文乱码解决方案 (1)
- servlet开发中文乱码解决方案 (1)
- web文本框初始提示 (1)
- web文本框初始提示 (0)
- xml (1)
- java中的加密技术 (1)
- 互联网 (1)
- mysql数据库 (1)
- java单例模式 (1)
- gson转json (1)
最新评论
sqlLite操作
SqlLite建库建表,增删改查DAO,如果不够清楚的话,还可以参考:http://blog.csdn.net/vrix/article/details/6717090
package com.shzz.wms.dao;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;
import com.shzz.wms.common.TableNames;
import com.shzz.wms.pojo.TGoods;
import com.shzz.wms.pojo.TSeller;
import com.shzz.wms.pojo.TStock;
public class SQLiteDatabaseDao {
private SQLiteDatabase mDb;
private Activity activity;
public SQLiteDatabaseDao(Activity activity) {
this.activity = activity;
mDb = activity.openOrCreateDatabase("WeakProject.db",
SQLiteDatabase.CREATE_IF_NECESSARY, null);
}
public int initTSeller(String table, List<TSeller> tsList) {
int resultFlag = 0;
for (TSeller ts : tsList) {
ContentValues values = new ContentValues();
values.put("SellerName", ts.getSellerName());
values.put("Address", ts.getAddress());
values.put("Contact", ts.getContact());
values.put("ContactNum", ts.getContactNum());
mDb.insert(table, null, values);
resultFlag = resultFlag + 1;
}
return resultFlag;
}
/************ 对数据库的操作 ***********************/
// 获取所有数据库的名称
public String[] getDatabasesList() {
return activity.databaseList();
}
// 创建一个数据库
public void createDatabase(String db) {
activity.openOrCreateDatabase(db, SQLiteDatabase.CREATE_IF_NECESSARY,
null);
}
// 删除一个数据库
public void dropDatabase(String db) {
try {
activity.deleteDatabase(db);
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "删除数据库失败",
Toast.LENGTH_LONG).show();
}
}
/************ 对数据库的表的属性添加修改操作 ***********************/
// 获取某个数据库的表的名称
public String getTablesList() {
Cursor c = mDb
.rawQuery(
"select name from sqlite_master where type='table' order by name",
null);
StringBuffer str = new StringBuffer();
str.append("表的名称为:\n");
while (c.moveToNext()) {
str.append(c.getString(0) + "\n");
}
c.close();
return str.toString();
}
// 创建表
public void createTable(String table) {
try {
String tables[] = table.split(",");
String createMSUserSQL = "create table if not exists " + tables[0]
+ " (User_ID text primary key not null, "
+ "User_Name text, " + "Branch text, " + "Password text, "
+ "Email text, " + "Role_Code text, " + "User_Dep text, "
+ "Mobile text, " + "Birthday text, " + "LiveAdress text, "
+ "IDCARD text, " + "Position text, " + "Sex text, "
+ "Valid integer, " + "Deleted_Flag integer, "
+ "Created_By text, " + "Created_Date timestamp, "
+ "Updated_By text, " + "Updated_Date timestamp " + ");";
String createTSellerSQL = "create table if not exists " + tables[1]
+ " (" + "ID integer primary key autoincrement, "
+ "SellerExtraName text, " + "Remark text, "
+ "SellerName text, " + "Address text, " + "Contact text, "
+ "ContactNum text, " + "Deleted_Flag integer, "
+ "Created_By text, " + "Created_Date timestamp, "
+ "Updated_By text, " + "Updated_Date timestamp " + ");";
String createTGoodsSQL = "create table if not exists " + tables[2]
+ "(" + "ID integer primary key autoincrement,"
+ "GoodsID text," + "GoodsName text," + "SellerID integer,"
+ "Specification text," + "Unit text,"
+ "Deleted_Flag integer," + "Created_By text,"
+ "Created_Date timestamp," + "Updated_By text,"
+ "Updated_Date timestamp);";
String createTStockSQL = "create table if not exists " + tables[3]
+ "(" + "ID integer primary key autoincrement,"
+ "StockID integer," + "GoodsID text,"
+ "SellerID integer," + "StockNum integer,"
+ "Deleted_Flag integer," + "Created_By text,"
+ "Created_Date timestamp," + "Updated_By text,"
+ "SellerName text,"+ "Updated_Date timestamp" + ");";
// mDb.execSQL(createMSUserSQL);//用户主表
mDb.execSQL(createTSellerSQL);//商家主表
mDb.execSQL(createTGoodsSQL);//货品主表
mDb.execSQL(createTStockSQL);//库存主表
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "数据表创建失败",
Toast.LENGTH_LONG).show();
}
}
// 删除一个表
public void dropTable(String table) {
try {
mDb.execSQL("drop table if exists " + table);
Toast.makeText(activity.getApplicationContext(), "数据表删除成功",
Toast.LENGTH_SHORT).show();
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "数据表删除失败",
Toast.LENGTH_LONG).show();
}
}
// 修改表--重命名表名
public boolean alterTableRenameTable(SQLiteDatabase mDb, String oldTable,
String newTableName) {
try {
mDb.execSQL("alter table " + oldTable + " rename to "
+ newTableName + ";");
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "数据表重命名失败",
Toast.LENGTH_LONG).show();
return false;
}
return true;
}
// 修改表--添加一列
// @table 需要修改的table名
// @column 添加的列的名称
// @type 列的类型,如text,varchar等
public boolean alterTableAddColumn(SQLiteDatabase mDb, String table,
String column, String type) {
try {
mDb.execSQL("alter table " + table + " add column " + column
+ type + " ;");
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "数据表添加失败",
Toast.LENGTH_LONG).show();
return false;
}
return true;
}
// 获取表的列的名称
public String getTableColumns(String table) {
Cursor c = getAllData(table);
String[] columns = c.getColumnNames();
String str = table + ":\n";
for (String s : columns) {
str += s + "\n";
}
c.close();
return str;
}
/************ 对数据库的表数据增删改查操作 ***********************/
// 添加一条数据
public void insertTSeller(String table, TSeller ts) {
ContentValues values = new ContentValues();
values.put("SellerExtraName", ts.getSellerExtraName());
values.put("SellerName", ts.getSellerName());
values.put("Contact", ts.getContact());
values.put("ContactNum", ts.getContactNum());
values.put("Remark", ts.getRemark());
values.put("Address", ts.getAddress());
values.put("Created_Date", ts.getCreated_Date());
try {
mDb.insert(table, null, values);
Toast.makeText(activity.getApplicationContext(), "添加数据成功!",
Toast.LENGTH_LONG).show();
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "添加数据失败!",
Toast.LENGTH_LONG).show();
}
}
/*
*
* 删除一条数据
*/
public boolean delete(String table, int id) {
String whereClause = "id=?";
String[] whereArgs = new String[] { String.valueOf(id) };
try {
mDb.delete(table, whereClause, whereArgs);
Toast.makeText(activity.getApplicationContext(), "删除数据成功!",
Toast.LENGTH_LONG).show();
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "删除数据失败!",
Toast.LENGTH_LONG).show();
return false;
}
return true;
}
/*
*
* 修改一条数据
*/
public void updateTSeller(String table, TSeller ts) {
ContentValues values = new ContentValues();
values.put("SellerName", ts.getSellerName());
values.put("Address", ts.getAddress());
values.put("Contact", ts.getContact());
values.put("ContactNum", ts.getContactNum());
String whereClause = "ID=?";
String[] whereArgs = new String[] { String.valueOf(ts.getId()) };
try {
mDb.update(table, values, whereClause, whereArgs);
Toast.makeText(activity.getApplicationContext(), "修改数据数据成功!",
Toast.LENGTH_LONG).show();
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "修改数据数据失败!",
Toast.LENGTH_LONG).show();
}
}
public Cursor queryById(String table, int id) {
/*
* 第一个参数String:表名 第二个参数String[]:要查询的列名 第三个参数String:查询条件
* 第四个参数String[]:查询条件的参数 第五个参数String:对查询的结果进行分组 第六个参数String:对分组的结果进行限制
* 第七个参数String:对查询的结果进行排序
*/
String[] columns = new String[] { "id", "username", "info" };
String selection = "id=?";
String[] selectionArgs = { String.valueOf(id) };
String groupBy = null;
String having = null;
String orderBy = null;
return mDb.query(table, columns, selection, selectionArgs, groupBy,
having, orderBy);
}
public Cursor queryBySellerName(String table, String whereArgers) {
/*
* 第一个参数String:表名 第二个参数String[]:要查询的列名 第三个参数String:查询条件
* 第四个参数String[]:查询条件的参数 第五个参数String:对查询的结果进行分组 第六个参数String:对分组的结果进行限制
* 第七个参数String:对查询的结果进行排序
*/
String[] columns = new String[] { "ID", "SellerName", "Address",
"Contact", "ContactNum", "Deleted_Flag", "Created_By",
"Created_Date", "Updated_By", "Updated_Date" };
String selection = "SellerName like ?";
String[] selectionArgs = { "%" + whereArgers + "%" };
String groupBy = null;
String having = null;
String orderBy = null;
return mDb.query(table, columns, selection, selectionArgs, groupBy,
having, orderBy);
}
public Cursor getAllData(String table) {
// 遍历表所有数据
return mDb.rawQuery("select * from " + table, null);
}
public List<TSeller> getTSellerAllPoints(String table) {
List<TSeller> tsList = new ArrayList<TSeller>();
Cursor cursor = mDb.rawQuery("select * from " + table, null);
while (cursor.moveToNext()) {
TSeller point = new TSeller();
point.setId(cursor.getInt(cursor.getColumnIndex("ID")));
point.setSellerExtraName(cursor.getString(cursor.getColumnIndex("SellerExtraName")));
point.setSellerName(cursor.getString(cursor
.getColumnIndex("SellerName")));
point.setContact(cursor.getString(cursor.getColumnIndex("Contact")));
point.setContactNum(cursor.getString(cursor
.getColumnIndex("ContactNum")));
point.setRemark(cursor.getString(cursor.getColumnIndex("Remark")));
point.setAddress(cursor.getString(cursor.getColumnIndex("Address")));
tsList.add(point);
}
cursor.close();
return tsList;
}
public void finish() {
mDb.close();
}
public void truncateTablle(String table) {
mDb.execSQL("delete from " + table);
}
public List<TSeller> getSellerNameBySellerIDs(String t_Seller, String t_Goods,
String goodId) {
List<TSeller> tSellerList = new ArrayList<TSeller>();
String strSQL = "select ID,SellerName from "+ t_Seller +" where ID in (select SellerID from "+t_Goods+" where GoodsID = '"+goodId+"')";
Cursor cursor = mDb.rawQuery(strSQL, null);
while(cursor.moveToNext()){
TSeller point = new TSeller();
point.setId(cursor.getInt(cursor.getColumnIndex("ID")));
point.setSellerName(cursor.getString(cursor.getColumnIndex("SellerName")));
tSellerList.add(point);
}
cursor.close();
return tSellerList;
}
public TGoods getGoodsNameByGoodsIDAndSellerID(String goodsId, int sellerId) {
TGoods tgoods = new TGoods();
String strSQL = "select GoodsName,Specification,Unit from "+TableNames.T_Goods+" where GoodsID='"+goodsId+"' and SellerID="+sellerId;
Cursor cursor = mDb.rawQuery(strSQL, null);
while(cursor.moveToNext()){
tgoods.setGoodsName(cursor.getString(cursor.getColumnIndex("GoodsName")).trim());
tgoods.setSpecification(cursor.getString(cursor.getColumnIndex("Specification")).trim());
tgoods.setUnit(cursor.getString(cursor.getColumnIndex("Unit")).trim());
break;
}
cursor.close();
return tgoods;
}
public void saveTStock(TStock ts) {
try {
saveTStock(ts,TableNames.T_Stock);
// saveTStockHistory(ts,TableNames.T_StockHistory);
} catch (Exception e) {
e.printStackTrace();
}
}
private void saveTStockHistory(TStock ts, String t_StockHistory) {
// TODO Auto-generated method stub
}
private void saveTStock(TStock ts, String t_Stock) {
ContentValues values = new ContentValues();
values.put("GoodsID", ts.getGoodsID());
values.put("SellerID", ts.getSellerID());
values.put("StockNum", ts.getNum());
values.put("Created_Date", ts.getCreated_Date());
try {
mDb.insert(t_Stock, null, values);
Toast.makeText(activity.getApplicationContext(), "添加数据成功!",
Toast.LENGTH_LONG).show();
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "添加数据失败!",
Toast.LENGTH_LONG).show();
}
}
public void selectInsertData() {
String strSQL = "select * from "+ TableNames.T_Stock;
Cursor cursor = mDb.rawQuery(strSQL, null);
while(cursor.moveToNext()){
System.out.println(
"ID:"+cursor.getInt(cursor.getColumnIndex("ID"))
+" GoodsID:"+cursor.getString(cursor.getColumnIndex("GoodsID")).trim()
+" SellerID:"+cursor.getInt(cursor.getColumnIndex("SellerID"))
+" StockNum:"+cursor.getInt(cursor.getColumnIndex("StockNum"))
+" Created_Date:"+cursor.getString(cursor.getColumnIndex("Created_Date"))
);
}
cursor.close();
}
}
package com.shzz.wms.dao;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;
import com.shzz.wms.common.TableNames;
import com.shzz.wms.pojo.TGoods;
import com.shzz.wms.pojo.TSeller;
import com.shzz.wms.pojo.TStock;
public class SQLiteDatabaseDao {
private SQLiteDatabase mDb;
private Activity activity;
public SQLiteDatabaseDao(Activity activity) {
this.activity = activity;
mDb = activity.openOrCreateDatabase("WeakProject.db",
SQLiteDatabase.CREATE_IF_NECESSARY, null);
}
public int initTSeller(String table, List<TSeller> tsList) {
int resultFlag = 0;
for (TSeller ts : tsList) {
ContentValues values = new ContentValues();
values.put("SellerName", ts.getSellerName());
values.put("Address", ts.getAddress());
values.put("Contact", ts.getContact());
values.put("ContactNum", ts.getContactNum());
mDb.insert(table, null, values);
resultFlag = resultFlag + 1;
}
return resultFlag;
}
/************ 对数据库的操作 ***********************/
// 获取所有数据库的名称
public String[] getDatabasesList() {
return activity.databaseList();
}
// 创建一个数据库
public void createDatabase(String db) {
activity.openOrCreateDatabase(db, SQLiteDatabase.CREATE_IF_NECESSARY,
null);
}
// 删除一个数据库
public void dropDatabase(String db) {
try {
activity.deleteDatabase(db);
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "删除数据库失败",
Toast.LENGTH_LONG).show();
}
}
/************ 对数据库的表的属性添加修改操作 ***********************/
// 获取某个数据库的表的名称
public String getTablesList() {
Cursor c = mDb
.rawQuery(
"select name from sqlite_master where type='table' order by name",
null);
StringBuffer str = new StringBuffer();
str.append("表的名称为:\n");
while (c.moveToNext()) {
str.append(c.getString(0) + "\n");
}
c.close();
return str.toString();
}
// 创建表
public void createTable(String table) {
try {
String tables[] = table.split(",");
String createMSUserSQL = "create table if not exists " + tables[0]
+ " (User_ID text primary key not null, "
+ "User_Name text, " + "Branch text, " + "Password text, "
+ "Email text, " + "Role_Code text, " + "User_Dep text, "
+ "Mobile text, " + "Birthday text, " + "LiveAdress text, "
+ "IDCARD text, " + "Position text, " + "Sex text, "
+ "Valid integer, " + "Deleted_Flag integer, "
+ "Created_By text, " + "Created_Date timestamp, "
+ "Updated_By text, " + "Updated_Date timestamp " + ");";
String createTSellerSQL = "create table if not exists " + tables[1]
+ " (" + "ID integer primary key autoincrement, "
+ "SellerExtraName text, " + "Remark text, "
+ "SellerName text, " + "Address text, " + "Contact text, "
+ "ContactNum text, " + "Deleted_Flag integer, "
+ "Created_By text, " + "Created_Date timestamp, "
+ "Updated_By text, " + "Updated_Date timestamp " + ");";
String createTGoodsSQL = "create table if not exists " + tables[2]
+ "(" + "ID integer primary key autoincrement,"
+ "GoodsID text," + "GoodsName text," + "SellerID integer,"
+ "Specification text," + "Unit text,"
+ "Deleted_Flag integer," + "Created_By text,"
+ "Created_Date timestamp," + "Updated_By text,"
+ "Updated_Date timestamp);";
String createTStockSQL = "create table if not exists " + tables[3]
+ "(" + "ID integer primary key autoincrement,"
+ "StockID integer," + "GoodsID text,"
+ "SellerID integer," + "StockNum integer,"
+ "Deleted_Flag integer," + "Created_By text,"
+ "Created_Date timestamp," + "Updated_By text,"
+ "SellerName text,"+ "Updated_Date timestamp" + ");";
// mDb.execSQL(createMSUserSQL);//用户主表
mDb.execSQL(createTSellerSQL);//商家主表
mDb.execSQL(createTGoodsSQL);//货品主表
mDb.execSQL(createTStockSQL);//库存主表
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "数据表创建失败",
Toast.LENGTH_LONG).show();
}
}
// 删除一个表
public void dropTable(String table) {
try {
mDb.execSQL("drop table if exists " + table);
Toast.makeText(activity.getApplicationContext(), "数据表删除成功",
Toast.LENGTH_SHORT).show();
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "数据表删除失败",
Toast.LENGTH_LONG).show();
}
}
// 修改表--重命名表名
public boolean alterTableRenameTable(SQLiteDatabase mDb, String oldTable,
String newTableName) {
try {
mDb.execSQL("alter table " + oldTable + " rename to "
+ newTableName + ";");
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "数据表重命名失败",
Toast.LENGTH_LONG).show();
return false;
}
return true;
}
// 修改表--添加一列
// @table 需要修改的table名
// @column 添加的列的名称
// @type 列的类型,如text,varchar等
public boolean alterTableAddColumn(SQLiteDatabase mDb, String table,
String column, String type) {
try {
mDb.execSQL("alter table " + table + " add column " + column
+ type + " ;");
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "数据表添加失败",
Toast.LENGTH_LONG).show();
return false;
}
return true;
}
// 获取表的列的名称
public String getTableColumns(String table) {
Cursor c = getAllData(table);
String[] columns = c.getColumnNames();
String str = table + ":\n";
for (String s : columns) {
str += s + "\n";
}
c.close();
return str;
}
/************ 对数据库的表数据增删改查操作 ***********************/
// 添加一条数据
public void insertTSeller(String table, TSeller ts) {
ContentValues values = new ContentValues();
values.put("SellerExtraName", ts.getSellerExtraName());
values.put("SellerName", ts.getSellerName());
values.put("Contact", ts.getContact());
values.put("ContactNum", ts.getContactNum());
values.put("Remark", ts.getRemark());
values.put("Address", ts.getAddress());
values.put("Created_Date", ts.getCreated_Date());
try {
mDb.insert(table, null, values);
Toast.makeText(activity.getApplicationContext(), "添加数据成功!",
Toast.LENGTH_LONG).show();
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "添加数据失败!",
Toast.LENGTH_LONG).show();
}
}
/*
*
* 删除一条数据
*/
public boolean delete(String table, int id) {
String whereClause = "id=?";
String[] whereArgs = new String[] { String.valueOf(id) };
try {
mDb.delete(table, whereClause, whereArgs);
Toast.makeText(activity.getApplicationContext(), "删除数据成功!",
Toast.LENGTH_LONG).show();
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "删除数据失败!",
Toast.LENGTH_LONG).show();
return false;
}
return true;
}
/*
*
* 修改一条数据
*/
public void updateTSeller(String table, TSeller ts) {
ContentValues values = new ContentValues();
values.put("SellerName", ts.getSellerName());
values.put("Address", ts.getAddress());
values.put("Contact", ts.getContact());
values.put("ContactNum", ts.getContactNum());
String whereClause = "ID=?";
String[] whereArgs = new String[] { String.valueOf(ts.getId()) };
try {
mDb.update(table, values, whereClause, whereArgs);
Toast.makeText(activity.getApplicationContext(), "修改数据数据成功!",
Toast.LENGTH_LONG).show();
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "修改数据数据失败!",
Toast.LENGTH_LONG).show();
}
}
public Cursor queryById(String table, int id) {
/*
* 第一个参数String:表名 第二个参数String[]:要查询的列名 第三个参数String:查询条件
* 第四个参数String[]:查询条件的参数 第五个参数String:对查询的结果进行分组 第六个参数String:对分组的结果进行限制
* 第七个参数String:对查询的结果进行排序
*/
String[] columns = new String[] { "id", "username", "info" };
String selection = "id=?";
String[] selectionArgs = { String.valueOf(id) };
String groupBy = null;
String having = null;
String orderBy = null;
return mDb.query(table, columns, selection, selectionArgs, groupBy,
having, orderBy);
}
public Cursor queryBySellerName(String table, String whereArgers) {
/*
* 第一个参数String:表名 第二个参数String[]:要查询的列名 第三个参数String:查询条件
* 第四个参数String[]:查询条件的参数 第五个参数String:对查询的结果进行分组 第六个参数String:对分组的结果进行限制
* 第七个参数String:对查询的结果进行排序
*/
String[] columns = new String[] { "ID", "SellerName", "Address",
"Contact", "ContactNum", "Deleted_Flag", "Created_By",
"Created_Date", "Updated_By", "Updated_Date" };
String selection = "SellerName like ?";
String[] selectionArgs = { "%" + whereArgers + "%" };
String groupBy = null;
String having = null;
String orderBy = null;
return mDb.query(table, columns, selection, selectionArgs, groupBy,
having, orderBy);
}
public Cursor getAllData(String table) {
// 遍历表所有数据
return mDb.rawQuery("select * from " + table, null);
}
public List<TSeller> getTSellerAllPoints(String table) {
List<TSeller> tsList = new ArrayList<TSeller>();
Cursor cursor = mDb.rawQuery("select * from " + table, null);
while (cursor.moveToNext()) {
TSeller point = new TSeller();
point.setId(cursor.getInt(cursor.getColumnIndex("ID")));
point.setSellerExtraName(cursor.getString(cursor.getColumnIndex("SellerExtraName")));
point.setSellerName(cursor.getString(cursor
.getColumnIndex("SellerName")));
point.setContact(cursor.getString(cursor.getColumnIndex("Contact")));
point.setContactNum(cursor.getString(cursor
.getColumnIndex("ContactNum")));
point.setRemark(cursor.getString(cursor.getColumnIndex("Remark")));
point.setAddress(cursor.getString(cursor.getColumnIndex("Address")));
tsList.add(point);
}
cursor.close();
return tsList;
}
public void finish() {
mDb.close();
}
public void truncateTablle(String table) {
mDb.execSQL("delete from " + table);
}
public List<TSeller> getSellerNameBySellerIDs(String t_Seller, String t_Goods,
String goodId) {
List<TSeller> tSellerList = new ArrayList<TSeller>();
String strSQL = "select ID,SellerName from "+ t_Seller +" where ID in (select SellerID from "+t_Goods+" where GoodsID = '"+goodId+"')";
Cursor cursor = mDb.rawQuery(strSQL, null);
while(cursor.moveToNext()){
TSeller point = new TSeller();
point.setId(cursor.getInt(cursor.getColumnIndex("ID")));
point.setSellerName(cursor.getString(cursor.getColumnIndex("SellerName")));
tSellerList.add(point);
}
cursor.close();
return tSellerList;
}
public TGoods getGoodsNameByGoodsIDAndSellerID(String goodsId, int sellerId) {
TGoods tgoods = new TGoods();
String strSQL = "select GoodsName,Specification,Unit from "+TableNames.T_Goods+" where GoodsID='"+goodsId+"' and SellerID="+sellerId;
Cursor cursor = mDb.rawQuery(strSQL, null);
while(cursor.moveToNext()){
tgoods.setGoodsName(cursor.getString(cursor.getColumnIndex("GoodsName")).trim());
tgoods.setSpecification(cursor.getString(cursor.getColumnIndex("Specification")).trim());
tgoods.setUnit(cursor.getString(cursor.getColumnIndex("Unit")).trim());
break;
}
cursor.close();
return tgoods;
}
public void saveTStock(TStock ts) {
try {
saveTStock(ts,TableNames.T_Stock);
// saveTStockHistory(ts,TableNames.T_StockHistory);
} catch (Exception e) {
e.printStackTrace();
}
}
private void saveTStockHistory(TStock ts, String t_StockHistory) {
// TODO Auto-generated method stub
}
private void saveTStock(TStock ts, String t_Stock) {
ContentValues values = new ContentValues();
values.put("GoodsID", ts.getGoodsID());
values.put("SellerID", ts.getSellerID());
values.put("StockNum", ts.getNum());
values.put("Created_Date", ts.getCreated_Date());
try {
mDb.insert(t_Stock, null, values);
Toast.makeText(activity.getApplicationContext(), "添加数据成功!",
Toast.LENGTH_LONG).show();
} catch (SQLException e) {
Toast.makeText(activity.getApplicationContext(), "添加数据失败!",
Toast.LENGTH_LONG).show();
}
}
public void selectInsertData() {
String strSQL = "select * from "+ TableNames.T_Stock;
Cursor cursor = mDb.rawQuery(strSQL, null);
while(cursor.moveToNext()){
System.out.println(
"ID:"+cursor.getInt(cursor.getColumnIndex("ID"))
+" GoodsID:"+cursor.getString(cursor.getColumnIndex("GoodsID")).trim()
+" SellerID:"+cursor.getInt(cursor.getColumnIndex("SellerID"))
+" StockNum:"+cursor.getInt(cursor.getColumnIndex("StockNum"))
+" Created_Date:"+cursor.getString(cursor.getColumnIndex("Created_Date"))
);
}
cursor.close();
}
}
相关推荐
7. **UI优化**:为了提高用户体验,可以使用进度条显示加载状态,或者在数据加载完成前禁用列表框,防止用户在数据未加载完毕时进行操作。 通过以上技术手段,可以有效地处理60万条数据的快速显示问题。易语言和...
在这个"Android数据库SQLlite操作demo"中,我们将深入探讨如何在Android应用中实现SQLite数据库的使用,特别是涉及到用户注册、登录以及数据的增删查改功能。 首先,让我们来看看如何创建一个简单的用户注册和登录...
try{ /* 初始化并创建数据库 */ dbHelper = new SQLiteHelper(this, DB_NAME, null, DB_VERSION); /* 创建表 */ db = dbHelper.getWritableDatabase(); //调用SQLiteHelper.OnCreate() ...
android 数据库操作 查询:select id,name from t_student; 更新:update t_student set name=’verygood’ where id=2; 删除:delete from t_student where id=2; 排序:select id,name from t_student ...
类似j2ee里面的dbutil类一样,通过反射包装了android中sqllite的操作。例如,对News的CRUD操作。例如下面代码: 只需要定义一个News.java DAO newsDao = new DAOImpl(mContext, News.class); List<News> list = ...
标题中的“flex sqlite操作”指的是使用Adobe Flex与SQLite数据库进行交互的技术。Flex是一种基于ActionScript的开放源代码框架,常用于构建富互联网应用程序(RIA)。SQLite则是一个轻量级的、自包含的、无服务器的...
5. **SQLite操作**: 标签"sqllite操作"意味着压缩包中的示例可能涵盖了创建数据库、表,执行CRUD操作(Create、Read、Update、Delete),事务处理,以及可能的错误处理和性能优化。 6. **ASP.NET集成**: 虽然主要...
在标题"SQLlite数据库操作易语言源码"中,我们可以理解为这是一个使用易语言编写的程序,它实现了对SQLite数据库的基本操作。这个程序可能包含了创建数据库、打开数据库、执行SQL语句、查询数据、插入数据、更新数据...
。net操作sqllite的帮助类,非常全面基本能用到的方法都有了,需要的可以下载下来拷贝到程序中哦、
这是一个针对System.Data.SQLite的数据库常规操作封装的C#通用类,调用此类可以快速的加快开发速度,直接调用即可,里面也有详细的注释说明!
java 操作sqllite的jar包,附带java代码。 package com.nsxx.qp.util; import java.sql.*; public class SqlLite { public static void main(String[] args) { try { //连接SQLite的JDBC Class.forName("org...
`sqlLite.class.php`和`lite.php`可能是两个用于PHP操作SQLite数据库的类库或脚本。让我们深入探讨这两个文件可能包含的内容以及PHP操作SQLite的相关知识点。 1. **SQLite数据库连接** 在PHP中,可以使用`sqlite_...
此外,`SQLite3`类还提供了其他高级功能,如准备和执行预编译的SQL语句(`prepare()`和`execute()`),以及创建和操作索引、视图等。 在实际开发中,为了提高代码的可维护性和安全性,推荐使用参数化查询来防止SQL...
开发时在使用sqllite数据库时,可以直接用它操作数据库,对数据进行增删改查,以及创建表结构
SQLite支持多种操作系统,包括Windows、Linux和macOS等,并且广泛应用于移动设备、嵌入式系统以及桌面应用。在WinForm应用中,SQLite可以作为一个便捷的数据存储解决方案。 本文将详细讲解如何在WinForm应用中使用...
本话题主要聚焦于SQLite的批量插入操作,这是一种提高数据导入效率的重要技术。 批量插入在处理大量数据时尤其有用,它可以显著减少与数据库交互的次数,从而降低系统资源的消耗并提升性能。在SQLite中,我们可以...
SqliteHelper.cs是封装了C#项目里对sqlite的-增删改查等基本操作的小巧类文件,希望对大家有帮助。
C++与SQLite的结合使用是将数据库操作集成到C++应用程序中的常见方法。SQLite是一个轻量级、嵌入式的关系型数据库,它不需要独立的服务器进程,并且支持SQL标准。以下是一些关于如何在C++中操作SQLite的关键知识点:...
本主题主要关注如何使用SQLite数据库查看工具以及在Java环境中操作SQLite数据库。 首先,SQLiteSpy_1.9.1是SQLite数据库的一个可视化查看工具,它允许用户直观地浏览数据库结构、执行SQL查询、查看和编辑数据。...