Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQLiteexception table triplog has no column named name

 
Michelle Lot
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am running into a trouble creating a table, it constantly tells me that there is no column named name.
I have searched for same cases online but still did not help.
I am wondering if anyone has any idea?

Thanks in advance.





package com.example.roadtriplog;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteOpenHelper;

public class TripDB extends SQLiteOpenHelper {

public TripDB(Context applicationContext) {

super(applicationContext, "TripLogBook.db", null, 1);
// TODO Auto-generated constructor stub
}

//call when the DB is created for the 1st time
public void onCreate(SQLiteDatabase database){

//create a table in the SQLite

String query = "CREATE TABLE triplog ( tripId INTEGER PRIMARY KEY AUTOINCREMENT, "
+"date TEXT, "
+ "name TEXT, "
+"departFrom TEXT, "
+" destination TEXT, "
+"milesInTown TEXT, "
+" milesOnHighway TEXT, "
+"gasUnitPrice TEXT, "
+ "carRental TEXT, "
+"days TEXT)";


database.execSQL(query);

}

//update table, drop, add, etc
@Override
public void onUpgrade(SQLiteDatabase database,int previousVersion,int currentVersion){

String query = "DROP TABLE IF EXISTS triplog";
database.execSQL(query);
onCreate(database);

}

public void insertTrip(HashMap<String,String> queryValues){

//open a DB for reading and writing
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();



values.put("date", queryValues.get("date"));
values.put("name", queryValues.get("name"));
values.put("departFrom", queryValues.get("departFrom"));
values.put("destination", queryValues.get("destination"));
values.put("milesInTown", queryValues.get("milesInTown"));
values.put("milesOnHighway", queryValues.get("milesOnHighway"));
values.put("unitGasPrice", queryValues.get("unitGasPrice"));
values.put("carRental", queryValues.get("carRental"));
values.put("days", queryValues.get("days"));
//insert data in the triplog table created above
// database.insert(table, null, values)
database.insert("triplog", null, values);
database.close();

}


public int updateTrip(HashMap<String,String> queryValues){

//same as insertTripLog
SQLiteDatabase database =this.getWritableDatabase();
ContentValues values = new ContentValues();

values.put("date", queryValues.get("date"));
values.put("name", queryValues.get("name"));
values.put("departFrom", queryValues.get("departFrom"));
values.put("destination", queryValues.get("destination"));
values.put("milesInTown", queryValues.get("milesInTown"));
values.put("milesOnHighway", queryValues.get("milesOnHighway"));
values.put("unitGasPrice", queryValues.get("unitGasPrice"));
values.put("carRental", queryValues.get("carRental"));
values.put("days", queryValues.get("days"));


return database.update("triplog", values, "tripId" + "=?", new String[]{
queryValues.get("tripId")});

}

public void deleteTrip(String id){

SQLiteDatabase database = this.getWritableDatabase();

String deleteQuery = "DELETE FROM triplog WHERE tripId='"+ id +"'";
//execute query
database.execSQL(deleteQuery);

}

public ArrayList<HashMap<String,String>> getAllTrips(){

//ArrayList<HashMap<String,String>> tripArrayList;

//tripArrayList=new ArrayList<HashMap<String,String>> ();

ArrayList<HashMap<String, String>> tripArrayList = new ArrayList<HashMap<String, String>>();


String selectQuery = "SELECT * FROM triplog";


SQLiteDatabase database = this.getWritableDatabase();

//cursor provides read and write access
//raw query returns the result as a cursor
Cursor cursor = database.rawQuery(selectQuery, null);

//cursor moves to the first row

if (cursor.moveToFirst()){
do{

HashMap<String,String> tripMap=new HashMap<String,String>();

tripMap.put("tripId", cursor.getString(0));
tripMap.put("date", cursor.getString(1));
tripMap.put("name", cursor.getString(2));
tripMap.put("departFrom", cursor.getString(3));
tripMap.put("destination", cursor.getString(4));
tripMap.put("milesInTown", cursor.getString(5));
tripMap.put("milesOnHighway", cursor.getString(6));
tripMap.put("unitGasPrice", cursor.getString(7));
tripMap.put("carRental", cursor.getString(8));
tripMap.put("days", cursor.getString(9));

tripArrayList.add(tripMap);


}while(cursor.moveToNext());


}
return tripArrayList;
}

public HashMap<String,String> getTripInfo(String id){
HashMap<String,String> tripMap=new HashMap<String,String>();
//open DB read-only

SQLiteDatabase database=this.getReadableDatabase();

String selectQuery = "SELECT * FROM triplog WHERE tripId='"+ id +"'";

Cursor cursor =database.rawQuery(selectQuery, null);

if (cursor.moveToFirst()){
do{

//

// tripMap.put("tripId", cursor.getString(0));
tripMap.put("date", cursor.getString(1));
tripMap.put("name", cursor.getString(2));
tripMap.put("departFrom", cursor.getString(3));
tripMap.put("destination", cursor.getString(4));
tripMap.put("milesInTown", cursor.getString(5));
tripMap.put("milesOnHighway", cursor.getString(6));
tripMap.put("unitGasPrice", cursor.getString(7));
tripMap.put("carRentalPrice", cursor.getString(8));
tripMap.put("days", cursor.getString(9));

//no add to tripArrayList this time.


}while(cursor.moveToNext());


}

return tripMap;

}

}





06-09 13:33:54.120: D/dalvikvm(887): Not late-enabling CheckJNI (already on)
06-09 13:33:56.620: D/dalvikvm(887): GC_FOR_ALLOC freed 46K, 4% free 3212K/3332K, paused 38ms, total 40ms
06-09 13:33:56.620: I/dalvikvm-heap(887): Grow heap (frag case) to 4.275MB for 1127536-byte allocation
06-09 13:33:56.670: D/dalvikvm(887): GC_FOR_ALLOC freed 3K, 3% free 4310K/4436K, paused 39ms, total 39ms
06-09 13:33:57.090: D/gralloc_goldfish(887): Emulator without GPU emulation detected.
06-09 13:34:01.330: I/Choreographer(887): Skipped 55 frames! The application may be doing too much work on its main thread.
06-09 13:34:07.040: D/dalvikvm(887): GC_FOR_ALLOC freed 128K, 4% free 4693K/4888K, paused 33ms, total 41ms
06-09 13:34:19.570: E/SQLiteLog(887): (1) table triplog has no column named name
06-09 13:34:19.600: E/SQLiteDatabase(887): Error inserting carRental=2 days=2 name=werwer milesOnHighway=2 date=ewrweq departFrom=3 unitGasPrice=2 milesInTown=2 destination=e
06-09 13:34:19.600: E/SQLiteDatabase(887): android.database.sqlite.SQLiteException: table triplog has no column named name (code 1): , while compiling: INSERT INTO triplog(carRental,days,name,milesOnHighway,date,departFrom,unitGasPrice,milesInTown,destination) VALUES (?,?,?,?,?,?,?,?,?)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
06-09 13:34:19.600: E/SQLiteDatabase(887): at com.example.roadtriplog.TripDB.insertTrip(TripDB.java:71)
06-09 13:34:19.600: E/SQLiteDatabase(887): at com.example.roadtriplog.NewTrip.addNewTrip(NewTrip.java:109)
06-09 13:34:19.600: E/SQLiteDatabase(887): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 13:34:19.600: E/SQLiteDatabase(887): at java.lang.reflect.Method.invoke(Method.java:515)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.view.View$1.onClick(View.java:3818)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.view.View.performClick(View.java:4438)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.view.View$PerformClick.run(View.java:18422)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.os.Handler.handleCallback(Handler.java:733)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.os.Handler.dispatchMessage(Handler.java:95)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.os.Looper.loop(Looper.java:136)
06-09 13:34:19.600: E/SQLiteDatabase(887): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-09 13:34:19.600: E/SQLiteDatabase(887): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 13:34:19.600: E/SQLiteDatabase(887): at java.lang.reflect.Method.invoke(Method.java:515)
06-09 13:34:19.600: E/SQLiteDatabase(887): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-09 13:34:19.600: E/SQLiteDatabase(887): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-09 13:34:19.600: E/SQLiteDatabase(887): at dalvik.system.NativeStart.main(Native Method)

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you have a previous version of your app that had a database but did not have the name column?

Try clearing the app's data and reinstalling it.
 
Michelle Lot
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve, it worked for me by reinstalling!
Thanks a lot!

Michelle
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic