I have a string called str_train_no
and i want to create a database with the same name and so far i have tried
String name=str_Train_no+".db";
SQLiteDatabase traindb = openOrCreateDatabase(name,SQLiteDatabase.CREATE_IF_NECESSARY , null);
sql="CREATE TABLE IF NOT EXISTS "+str_Train_no+" ("
+"Stops VARCHAR);";
traindb.execSQL(sql);
Heres the Source code for the database declaration and insertion part
SQLiteDatabase db = openOrCreateDatabase( "Train_list.db", SQLiteDatabase.CREATE_IF_NECESSARY , null);
try {
final String CREATE_TABLE_TRAIN_LIST = "CREATE TABLE IF NOT EXISTS Train_list ("
+ "Train_name VARCHAR,"
+ "Train_no VARCHAR,"
+ "Train_start VARCHAR,"
+ "Train_end VARCHAR,"
+ "Seats_Available VARCHAR);";
db.execSQL(CREATE_TABLE_TRAIN_LIST);
Toast.makeText(admin_manipulation.this, "Table created", Toast.LENGTH_LONG).show();
String sql = "INSERT or replace INTO Train_list (Train_name, Train_no, Train_start, Train_end, Seats_Available) VALUES('"+str_Train_name + "',' " +str_Train_no + "', '" +str_Train_start+"','" +str_Train_end+"',' " +str_Train_seats +"');";
db.execSQL(sql);
Toast.makeText(admin_manipulation.this, "Inserted Sucessfully", Toast.LENGTH_SHORT).show();
String name=str_Train_no+".db";
SQLiteDatabase traindb = openOrCreateDatabase(name, SQLiteDatabase.CREATE_IF_NECESSARY , null);
sql="CREATE TABLE IF NOT EXISTS "+str_Train_no+" ("
+"Stops VARCHAR);";
traindb.execSQL(sql);
Toast.makeText(admin_manipulation.this, "Table "+str_Train_no+" verified", Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
Toast.makeText(admin_manipulation.this, "An Error has occured", Toast.LENGTH_SHORT).show();
}
and this keeps throwing an exception. Any ideas why? Thanks in advance!