Android : Delete Row In Database Table Given One Column Value - Which Is A String
Jul 22, 2010
I have a table with column headings: | _id (long) | Name (String) | x (integer) | y (integer) |
I want to delete the row in the table that has Name myName.
// In onCreate
dbHelper = new DBAdapter(this);
dbHelper.open()
// Function in DBAdapter class
public boolean deleteTitleGivenName(String myName)
{return dbHelper.delete(DATABASE_TABLE_2, KEY_NAME + "=" + myName, null) > 0;}
// Function call in java code
dbHelper.deleteTitleGivenName(myName); // this is where my code fails
dbHelper.close();
Just as a note: myName is for sure in the database. Also, I can not use the ROWID since I am getting myName from a ListView.
I just started programming with Android and I have tried for days to solve this problem.
Is my WHERE clause correct (KEY_NAME + "=" + myName)?
View 2 Replies
Nov 24, 2010
I have created a table named train_table in SQLite database with 3 columns. they are train_id, train_no and train_name. Now, i wrote a class in which i displayed the train_name in a list view. how do i get the related train_no in the next page? can anyone help me in sorting this problem.?
View 2 Replies
View Related
Apr 23, 2010
I have a database where I store two different kinds of data. One table is for favorite routes, the other stores the retrieved routes from a server.
I can retrieve the routes etc just fine. But after retrieving the first Route, pressing back or HOME, and then retrieving another route, the routes table is filled with all the old routes plus the new ones.
So my question: how do I delete ONLY the routes table and not the whole database because I don't want to delete the added favorites?
I found the following function in the android docs:
public int delete (String table, String whereClause, String[] whereArgs) and I tried to implement it, but I must pass a SQLiteDataBase as an argument. But how?
I implemented: public void deleteTableRoutes(SQLiteDataBase db){ db.delete("routes", null, null);}
But I want to call this function from a different class where I have no reference to the database.. so what do I have to pass as an argument? Or how do I get a reference to my database?
I build my database upon the code example of the NotePadExample from the dev docs.How to solve this problem?
This is an extract of my class from where I want to call deleteTableRoutes(...)
private String start_from;
private String destination;
private int hour;
private int min;
private int day;
private int month;
private Source source;
private List<Element> tempList;
private List<Element> routes;
private String startT = "";
private String arrivalT = "";
private String duration = "";
private String line = "";
private boolean first=true;
private List<ResultElement> finalResult;
private List<Element> results;
private DbAdapter mDbHelper;
View 3 Replies
View Related
Jul 29, 2010
I'm not big into UI programming so this may be an easy thing I overlooked. I am trying have a screen that shows 8 TextView in a 2 column x 4 row table. And, of course, I want the TextViews, that might have different lengths, to be centered. I tried this in a table layout, for obvious reasons but I feel like this is not the way to do it because it doesn't have much control where I put everything once it is in a row. Should I be using a different combinations of layouts or is there something I overlooked.
View 2 Replies
View Related
Nov 23, 2010
can I insert a new column into existing table. Because I had read somewhere that SQLite is limited on the ALTER TABLE command.
View 2 Replies
View Related
Aug 3, 2010
I am trying to create a basic datasheet in my application using a TableLayout. The first row contains the titles of each column. Every row thereafter is data. I would like the data to be scrollable while keeping the first title row visible (i.e. the first row would not scroll with the rest).I have tried something like the following (unsuccessfully)
View 1 Replies
View Related
Nov 17, 2010
How to create a table without primary key but it has one autoincrement column.
View 2 Replies
View Related
Apr 20, 2010
So I have an app on the market, and with an update I want to add some columns to the database. No problems so far. But I want to detect if the database in use is missing these columns, and add them if this is the case. I need this to be done dynamically and not just after the update to the new version, because the application is supposed to still be able to import older databases. Normally I would be able to use the PRAGMA query, but Im not sure how to do this with Android. I cant use execSQL since it is a query, and I cant figure out how to use PRAGMA with the query()-function.
Ofcourse I could just catch exceptions and then add the column, or always add the columns to each table before I start to work with it, but that is not a neat solution.
View 4 Replies
View Related
Mar 2, 2010
I am trying out this table layout in which there are three columns, each column utilizing the maximum space as they could (using strechColumn tag). Now when a column gets content which is too long, then table layout jumps of the screen.
How can i set the content of a column to wrap, so that table layout dont jump off the screen.
here is the XML code for table layout i used...
View 1 Replies
View Related
Feb 12, 2010
Suppose I have a view inside TableLayout, like this:
TableLayout tableLayout;
View view = (View)tableLayout.findViewById(R.id.control);
How can I find out the view's row/column within the TableLayout?
View 1 Replies
View Related
Jul 15, 2010
I have two files, one called "part1.txt" and another one called "part2.txt", which look like following
part1.txt part2.txt
lili like eating apple
lucy like playing football
Now i want to insert the contents of these two files into a single table with the schema
table_name(linefrompart1 varchar(100), linefrompart2 varchar(50))
My program reads the first file line by line and insert the data into the first column. But if it reads the second file and tries to insert the data line by line into the second column, it doesn't work the way i want. A table which i want should look like following
linefrompart1 linefrompart2
lili like eating apple
lucy like playing football
But instead i got the following table
linefrompart1 linefrompart2
lili null
lucy null
null like eating apple
null like playing football
Does somebody know how i can fix this problem?
View 1 Replies
View Related
Mar 9, 2010
Is it possible for my android application to dynamically adjust the no of column and no of row of my TableLayout based on orientation?
For example, when in landscape mode, the TableLayout is 3x2 and when
in portrait mode, the TableLayout is 2x3?
View 1 Replies
View Related
Oct 19, 2010
I'm requesting data from my server and receive a string in the form of 2|bit.ly|1||1| and | should be the separator. I thought the following piece of code should do the work
BufferedReader br = null; ...
br = new BufferedReader(new InputStreamReader(inputStream)); ...
String line; String[] columns; ContentValues values;
while((line = br.readLine())!=null) { columns = line.split("|"); ...
}
But after the line.split("|"); the columns contains 15 elements instead of expected 6. Taking a closer look at it's content reveals that each character in the string was stored in one array element. The code coming from server isn't encoded in any way in in the example I use only ASCII characters appear.
View 1 Replies
View Related
Nov 12, 2010
I read that the different entries in different tables are linked via the _ID column in that table. For example a contact might have an _ID = 1 I get via
ContactsContract.Contacts._ID
And now I want to read the phone number of that contact using
CODE:.............
This works fine, but what I would expect is that if the _ID of the contact is 1 that the _ID of the phone number is as well one since they belong together, but they are not equal. So the question is how does Android match these entries?
View 1 Replies
View Related
Oct 12, 2009
I have a database that I download external and save on my sdcard. But this database is also used for an iPhone app and has a column id and not _id (sqlite uses _id). How can i rename this column to _id?
View 4 Replies
View Related
May 31, 2009
Before I create a table, how can I know whether the table already exist in database? How to query?
View 3 Replies
View Related
Jul 28, 2009
I'm working at an application about SQLite database. I have inserted some table in an database file. But I don't know how to get all the tables' name using code. For example, I defined a database object SQLiteDatabase dataBase = SQLiteDatabase.openOrCreateDatabase(getDatabasePath("Mydatabase"), null); and how can I get all the table names stored in the database file "Mydatabase". Counld anyone give me some code.
View 9 Replies
View Related
Apr 20, 2010
how to clear a table in android database.
View 3 Replies
View Related
May 13, 2010
I have already having 2 tables in a database now i want to create a new table in that database it self how can i create?
View 3 Replies
View Related
Jan 22, 2009
to dear all Android developers, I need to know the UTC bias of my phone to correct the UTC time information I got from a site. I have read earlier posts and already found the solution to get TimeZone information from the "System.currentTimeMillis();" method. However, I need to translate the TimeZone (as like, "Asia/Taipei") to the UTC bias that it has to be (as like, "UTC+8" or other formats). Does anyone know the actual API solution? I have surveyed android.util.TimeUtils and found nothing to do this. The worst solution may I have is to build a "TimeZone/UTC" database table to translate this..
View 3 Replies
View Related
Oct 11, 2010
I am new to andriod.I am creating a table and inserting the values into table by using sql lite.Now i need to change vales based on the id.how can i done this pls post some code.
View 2 Replies
View Related
May 8, 2013
I am developing an application in android allowing the user to maintain his weight by providing him diet suggestions. I have done with that part and now, I need to display user weight tracking details using bar graph. I am able to fetch the Weight and Login date column data from the sqlite database to List<String>. I don't understand the way to put these values into a Bar Graph with Date Column data as X-axis and Weight column data as Y-axis.
View 1 Replies
View Related
Oct 20, 2009
I am working on a project for a belgium Tv Guide. Now I download a database (.db) file from a server to the sdcard to work with. In this database are 2 tabels, tvchannels and tvprograms. Now I can do several updates to the tvchannels table and i want to make a backup of this table to a lokal database file. How can i do that? I want to do this because I have to download a new database file every daye from the server and the channels that are choses are saved in the tvchannels database. I want to backup this database table and when the new database file (tvgids.db) is downloaded I want to replace the tvchannels database (from downloaded database file) with the backup from tvchannels..
View 6 Replies
View Related
Sep 12, 2010
I want my app to access database every hour and read next record from the table then update desctop widget and send notification. I know that there is AlarmManager which I can use to register my Intents but they are deleted when the phone is turned off or rebooted. Is there any other android class/service that I would update my application continuously even when I reboot my phone?
View 2 Replies
View Related
Jan 21, 2010
In Android when you upgrade a database all data is lost. I'm going through a phase of development right now that is forcing many database upgrades. I don't want to lose all my data (and have to manually re-enter it) each time I upgrade my database. I would like to store my data in flat files and load those flat files into their respective tables each time a database upgrade occurs.
My questions is: What is the best way to go about this on the Android platform? Where should I store the data files (res/raw???) What sql should I execute to load these files?
View 2 Replies
View Related
Nov 3, 2010
I want to read data from database and displayed it in table layout form. table will contain n rows and 2 columns. But row size is not fixed then how to show them in table layout format?
View 5 Replies
View Related
Nov 14, 2011
i'm trying to access (read & write) from non-default (example 2nd table) table of a sqlite database which i created using sqlite database browser. but somehow, i cant seems to find the way to access it.
Code:
public class DatabaseHelper extends SQLiteOpenHelper {
private static String DB_PATH = "/data/data/com.sg/databases/";
private static String DB_NAME = "TestDatabase";
private SQLiteDatabase myDatabase;
[code]...
select data method works, but i can only select from table 1 and not table 2
View 4 Replies
View Related
May 22, 2010
In my project, I would like to create a database with single table. I would also like to insert data on this table from word or excel document. is it possible? if so please how can I do it? some code snippets would be of great help. I have four different activities which I would like them to interact with this single table. the first is the main activity and its purpose is just to launch the other three activities according to user choice. so it has no interaction with the DB. but the other three activities will read from the table whenever called. Can you please tell me how to call the dbhelper on these activities? I am unable to do this and I am currently creating one db per each activity which is not the optimal way.
View 1 Replies
View Related
Jan 10, 2010
Maybe I'm going about this the wrong way, but if so, please correct me. Here is the situation: I have a query which returns URI strings for ringtones stored in a database.
I am trying to add a "column" to this cursor with the ringer "Title" (since this can change outside my program). I can successfully user RingtoneManager to get the title, but I cannot figure out how to add this "column" to the cursor data for later use. Here is what I have so far: Code...
View 2 Replies
View Related
Jul 9, 2010
I'm working on a android application that will display Strings to the user, and the user then has the option to add one to a favorite list. I have searched and searched and cannot find the proper way of doing this. I did get one open source project, everything worked until the user removed a favorite. The database would clear the row of data, but when a new row is added, it would behave as if the deleted row still had data, leaving blanks in the favorite list.
This is my insert method
public long insertString(String newString)
ContentValues newStringValue = new ContentValues();
newStringValue.put(KEY_STRING, newString);
return db.insert(DATABASE_TABLE, null, newStringValue);
The long returned will always increment even if i use the remove method:
public boolean removeString(long _rowIndex)
return db.delete(DATABASE_TABLE, KEY_ID + "=" + _rowIndex, null) > 0;
If I try to remove the third index, and the user removed a question at the third index, the method returns false, is there a way to completely remove all rows with no data?
View 2 Replies
View Related