Android 数据库与MapView总结
2010-11-05 00:54:34 来源:WEB开发网public String FieldNames[][];
public String FieldTypes[][];
public static String NO_CREATE_TABLES = "no talbes";
private String message = "";
public MySQLiteOpenHelper(Context context, String name,
CursorFactory factory, int version, String tableNames[],
String fielsNames[][], String fieldTypes[][]) {
super(context, name, factory, version);
TableNames = tableNames;
FieldNames = fielsNames;
FieldTypes = fieldTypes;
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
if (TableNames == null) {
message = NO_CREATE_TABLES;
return;
}
for (int i = 0; i < TableNames.length; i++) {
String sql = "create table " + TableNames[i] + " (";
for (int j = 0; j < FieldNames[i].length; j++) {
sql += FieldNames[i][j] + " " + FieldTypes[i][j] + ",";
}
sql = sql.substring(0, sql.length() - 1);
sql += ")";
db.execSQL(sql);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
for (int i = 0; i < TableNames[i].length(); i++) {
String sql = "DROP TABLE IF EXISTS " + TableNames[i];
db.execSQL(sql);
}
onCreate(db);
}
public void execute(String sql) throws java.sql.SQLException{
SQLiteDatabase db =this.getWritableDatabase();
db.execSQL(sql);
}
public Cursor select(String table,String[] columns,String selection,String[] selectionArgs,
String groupBy,String having,String orderBy
){SQLiteDatabase db=this.getReadableDatabase();
Cursor cursor =db.query(table, columns, selection, selectionArgs, groupBy,
更多精彩
赞助商链接