How to check a sql table exist or not??

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to check a sql table exist or not??

Postby The_One_Neo » Thu Apr 16, 2009 6:23 am

public class DatabaseHelper extends SQLiteOpenHelper{

public DatabaseHelper(Context context, String name, CursorFactory factory,
int version) {
super(context, name, null, version);
// TODO Auto-generated constructor stub
init();
}

@Override public void onCreate(SQLiteDatabase db) {}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}


private void init()
{
SQLiteDatabase Rdb = getReadableDatabase();
String Rsql = "select count(*) from sqlite_master where name='good' and type='U'";

try { Rdb.execSQL(Rsql);)
catch (SQLException Re) {
Log.e("ERROR", Re.toString());
SQLiteDatabase Wdb = getWritableDatabase();
String Wsql = "create table good(" + "stud_no text not null, "
+ "stud_name text );";
try { Wdb.execSQL(Wsql); }
catch (SQLException We) {
Log.e("ERROR", We.toString());
}
close();
}
}
}

if the table created, restart again the check str is fail

the Rsql right or not ??

please help me !
thanks
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Top

Postby WarrenFaith » Thu Apr 16, 2009 7:31 am

Use the JAVA-BUTTON!!! please...
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby The_One_Neo » Thu Apr 16, 2009 10:00 am

Are you sure?

i know the j2me have the api exist("name");

but android no have this api
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Postby nmc » Thu Apr 16, 2009 11:15 am

If you just want to know this for your 'create table' statement, then just use:
"create table if not exists good ("...
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby The_One_Neo » Thu Apr 16, 2009 11:38 am

Thanks nmc :)
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests