Jump to content

[Resolvido] [SQLite Android]Dúvidas Query


Recommended Posts

Não estou a prceber onde está o erro

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Sqlite{
final static String KEY_NEW= "_id";
final static String KEY_Buy = "pack_buy";
final static String KEY_NAME= "pack_name";
private final static String DATABASE_NAME = "Purshased";
private final static String DATABASE_TABLE = "PackNames";
private final static int DATABASE_VERSION = 1;
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
public static class DbHelper extends SQLiteOpenHelper{

 public DbHelper(Context context){
  super(context, DATABASE_NAME, null, DATABASE_VERSION);
  // TODO Auto-generated constructor stub
 public void onCreate(SQLiteDatabase db){
  // TODO Auto-generated constructor stub
  db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
 KEY_Buy + " TEXT NOT NULL, " +

 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  // TODO Auto-generated method stub
public Sqlite(Context c){
 ourContext = c;
public Sqlite open()throws SQLException{
 ourHelper = new DbHelper(ourContext);
 ourDatabase = ourHelper.getWritableDatabase();
 return this;
public void close(){
public long createEntry(String bUY) {
 // TODO Auto-generated method stub
 ContentValues cv = new ContentValues();
 cv.put(KEY_NAME, bUY);
 return ourDatabase.insert(DATABASE_TABLE, KEY_NEW, cv);
public String getData() {
 // TODO Auto-generated method stub
 String[] namePack = new String [] {KEY_NAME};
 Cursor cs = ourDatabase.rawQuery("SELECT " + DATABASE_TABLE + " (" +
   KEY_NAME +");", namePack);
  if (cs.moveToFirst()) {
   String a = cs.getString(cs.getColumnIndex("pack_name"));
   return a;
  return "";


04-12 15:19:32.599: E/AndroidRuntime(6374): FATAL EXCEPTION: main
04-12 15:19:32.599: E/AndroidRuntime(6374): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2012, result=-1, data=null} to activity {com.test.pot/com.test.LayoutOne}: android.database.sqlite.SQLiteException: no such column: pack_name: , while compiling: SELECT PackNames (pack_name);
Link to comment
Share on other sites

SELECT PackNames (pack_name);

Isto não me parece uma query bem feita.

Mas está lá escrito:

SQLiteException: no such column: pack_name: , while compiling: SELECT PackNames (pack_name);
Edited by KTachyon

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.