Jump to content




Recent Status Updates

  • Photo
      30 Sep
    rhossis

    laptop hard disk seated beneath motherboard but with no access panel. 7 hours to replace :(

    Show comments (3)
  • Photo
      19 Sep
    Chall

    I love it when you go to write a help thread, then while writing, you reach an enlightenment, and figure it out yourself.

    Show comments (3)
View All Updates

Developed by Kemal Taskin
Photo
- - - - -

[Help] Android.database.sqlite.sqliteexception: Can't Upgrade Read-Only Database From Version 0 To 1: /data/data/com.myapp.app/databases/mydb

android sqlite

  • Please log in to reply
2 replies to this topic

#1 kiddies

kiddies

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 129 posts

Posted 15 April 2012 - 06:24 PM

sorry i wanna ask about android database SQLite couse i found error when im running the application..
i was search some tutorial for creating database in android but not success when i was running it..i was searching too about solve that problem, but i cant solve that

here sources:
MySQLHelper.java
package com.kiddies.tsel;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class mySqlHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "tsel.db";
private static final int DATABASE_VERSION = 1;
//table name
public static final String TABLE = "roaming";
//columns
public static final String negara = "negara";
public static final String network = "network";
public static final String keindonesia = "indonesia";
public static final String local = "local";
public static final String kenegara = "kenegara";
public static final String terimatlp = "terimatlp";
public static final String sms = "sms";
public static final String gprs = "gprs";
public mySqlHelper(Context context){
  super(context, DATABASE_NAME, null, DATABASE_VERSION);
  // TODO Auto-Generated construct stub
}
public void onCreate(SQLiteDatabase db){
  String sql = "create table"+TABLE+"(_id"+"integer primary key autoincrement,"
+negara+"text not null,"+network+"text not null,"+keindonesia+"text not null,"
+local+"text not null,"+kenegara+"text not null,"+terimatlp+"text not null,"
+sms+"text not null,"+gprs+"text not null);";
  Log.d("Data", "onCretae:" + sql);
  db.execSQL(sql);
  ContentValues newValues = new ContentValues();
  newValues.put("negara", "singapure");
  newValues.put("network", "sinTel");
  newValues.put("keindonesia","Rp.15000");
  newValues.put("local", "Rp.7000");
  newValues.put("kenegara", "Rp.18000");
  newValues.put("terimatlp", "Rp.4000");
  newValues.put("gprs", "Rp.129/Kb");
  db.insert(TABLE, null, newValues);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
  db.execSQL("DROP TABLE IF EXIST " + TABLE);
  onCreate(db);
}
}

TselActivity.java
package com.kiddies.tsel;

import android.app.Activity;
import android.os.Bundle;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class TselActivity extends Activity {
    /** Called when the activity is first created. */
    mySqlHelper dbHelper;
    private TextView Jumlah;
    private Button but_Search;
    private EditText ed_Search;
    private TextView mytext;
    protected Cursor cursor;
    protected ListAdapter adapter;
    protected ListView List;
    @Override
    public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);
	    
	    dbHelper = new mySqlHelper(this);
	    mytext = (TextView) findViewById(R.id.TextView01);
	    but_Search = (Button) findViewById(R.id.But_Search);
	    ed_Search = (EditText) findViewById(R.id.Ed_Search);
	    List = (ListView) findViewById(R.id.ListView01);
	    Jumlah = (TextView) findViewById(R.id.text_jumlah);
	    
    }
    public void but_SearchClick(View v){
        try {
            SQLiteDatabase db = dbHelper.getReadableDatabase();
            cursor = db.rawQuery("SELECT _id, negara, network, keindonesia, local, kenegara, terimatlp, sms, gprs" +
                    "FROM roaming WHERE negara LIKE'%"+ed_Search.getTextColors().toString()+"%'", null);
            adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2,
                    cursor, new String[]{"negara"}, new int[] {
                            android.R.id.text1});
            List.setAdapter(adapter);
            cursor = db.rawQuery("select count(network) from roaming where negara LIKE'%"
                    +ed_Search.getText().toString()+"%'"+cursor.getInt(0), null);
            cursor.moveToFirst();
            Jumlah.setText("Jumlah:"+cursor.getInt(0));
    }
		    catch (Exception e)
		    {
		        mytext.setText(e.toString());
		    }
        }
    }

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <TextView
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    android:id="@+id/TextView01"
	    android:text="Enter Countries:"/>
<LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <EditText
	    android:id="@+id/Ed_Search"
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"></EditText>
    <Button
	    android:text="SEARCH"
	    android:id="@+id/But_Search"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:onClick="but_SearchClick"></Button>  
</LinearLayout>
    <TextView
	    android:id="@+id/text_jumlah"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content" />
    <ListView
	    android:id="@+id/ListView01"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"></ListView>
</LinearLayout>

help me for solve that problem..
  • 0

#2 WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderator
  • 17,133 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 16 April 2012 - 06:54 AM

Things that jump out at me:
1) Why is your database file readonly?
2) why are you creating a database that is version 0, when you need version 1?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3,451 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 17 April 2012 - 07:02 PM

Man it took me time but i just realized what happens !

Good news its very very easy to solve, lets check your sql string :

public static final String TABLE = "roaming";

String sql = "create table"+TABLE+"(_id"+"integer primary key autoincrement,"


the result of that is a misspelled sql query, look at it :
create tableroaming(_id+integer primary key autoincrement,
See, no spaces in between table keyword and table name, and if you check it up you will find its the same for the rest of added fields

make sure your string ends up a valid sql string and it will work just fine
  • 0





Also tagged with one or more of these keywords: android, sqlite